示例#1
0
func TestHealthResponse(t *testing.T) {
	out_chan := make(chan string, 1)

	data := NewMessage().SetData("is-healthy?")

	req := engine.NewRequest(proto.HealthTopic(engine.getIdent()))
	resp, err := req.Execute(data)
	if err != nil {
		t.Error(err)
	}

	msg := resp.Next()
	x := []string{}
	msg.GetData(&x)

	if len(x) > 0 {
		out_chan <- "healthy"
	} else {
		out_chan <- "false"
	}

	select {
	case result := <-out_chan:
		if result != "healthy" {
			t.Error("*Message should be healthy. Found", result)
		}
	case <-time.After(time.Second * 5):
		t.Error("*Message should be", PingResponse, "timed out instead")
	}
}
示例#2
0
func TestHealthSubscribe(t *testing.T) {
	engine.SetHealthCheckEnabled()

	topic := proto.HealthTopic(engine.getIdent())
	if has, _ := isReplySubscribed(topic); !has {
		t.Error(topic, "should have been subscribed")
	}
}
示例#3
0
func subscribeHealth(g *Gilmour) {
	health_topic := proto.HealthTopic(g.getIdent())
	handlerOpts := NewHandlerOpts().SetGroup("exclusive")

	g.ReplyTo(health_topic, func(r *Request, w *Message) {
		topics := []string{}

		resp_topic := proto.ResponseTopic("")

		for t, _ := range g.getAllSubscribers() {
			if strings.HasPrefix(t, resp_topic) || strings.HasPrefix(t, health_topic) {
				//Do Nothing, these are internal topics
			} else {
				topics = append(topics, t)
			}
		}

		w.SetData(topics)
	}, handlerOpts)
}