From f723651a6d65d0210ce39a84b983face2252ea3b Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 30 Oct 2013 15:46:01 -0700 Subject: [PATCH] fix test: should wait for watch response --- server/v2/tests/get_handler_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/v2/tests/get_handler_test.go b/server/v2/tests/get_handler_test.go index becca1ef2..d6ceae58a 100644 --- a/server/v2/tests/get_handler_test.go +++ b/server/v2/tests/get_handler_test.go @@ -116,9 +116,11 @@ func TestV2WatchKey(t *testing.T) { func TestV2WatchKeyWithIndex(t *testing.T) { tests.RunServer(func(s *server.Server) { var body map[string]interface{} + c := make(chan bool) go func() { resp, _ := tests.Get(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar?wait=true&waitIndex=5")) body = tests.ReadBodyJSON(resp) + c <- true }() // Make sure response didn't fire early. @@ -142,6 +144,14 @@ func TestV2WatchKeyWithIndex(t *testing.T) { // A response should follow from the GET above. time.Sleep(1 * time.Millisecond) + + select { + case <-c: + + default: + t.Fatal("cannot get watch result") + } + assert.NotNil(t, body, "") assert.Equal(t, body["action"], "set", "") assert.Equal(t, body["key"], "/foo/bar", "")