Browse Source

fix test: should wait for watch response

Xiang Li 12 years ago
parent
commit
f723651a6d
1 changed files with 10 additions and 0 deletions
  1. 10 0
      server/v2/tests/get_handler_test.go

+ 10 - 0
server/v2/tests/get_handler_test.go

@@ -116,9 +116,11 @@ func TestV2WatchKey(t *testing.T) {
 func TestV2WatchKeyWithIndex(t *testing.T) {
 func TestV2WatchKeyWithIndex(t *testing.T) {
 	tests.RunServer(func(s *server.Server) {
 	tests.RunServer(func(s *server.Server) {
 		var body map[string]interface{}
 		var body map[string]interface{}
+		c := make(chan bool)
 		go func() {
 		go func() {
 			resp, _ := tests.Get(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar?wait=true&waitIndex=5"))
 			resp, _ := tests.Get(fmt.Sprintf("http://%s%s", s.URL(), "/v2/keys/foo/bar?wait=true&waitIndex=5"))
 			body = tests.ReadBodyJSON(resp)
 			body = tests.ReadBodyJSON(resp)
+			c <- true
 		}()
 		}()
 
 
 		// Make sure response didn't fire early.
 		// Make sure response didn't fire early.
@@ -142,6 +144,14 @@ func TestV2WatchKeyWithIndex(t *testing.T) {
 
 
 		// A response should follow from the GET above.
 		// A response should follow from the GET above.
 		time.Sleep(1 * time.Millisecond)
 		time.Sleep(1 * time.Millisecond)
+
+		select {
+		case <-c:
+
+		default:
+			t.Fatal("cannot get watch result")
+		}
+
 		assert.NotNil(t, body, "")
 		assert.NotNil(t, body, "")
 		assert.Equal(t, body["action"], "set", "")
 		assert.Equal(t, body["action"], "set", "")
 		assert.Equal(t, body["key"], "/foo/bar", "")
 		assert.Equal(t, body["key"], "/foo/bar", "")