Browse Source

fix(test/server): avoid watch test timeout by moving json decode

These tests were timing out because the combination of the GET and JSON
decode was taking longer than the timeout. Pull the JSON decode out of
the go routine that is being timed.
Yicheng Qin 11 years ago
parent
commit
df2b565397
2 changed files with 6 additions and 8 deletions
  1. 3 4
      server/v1/tests/get_handler_test.go
  2. 3 4
      server/v2/tests/get_handler_test.go

+ 3 - 4
server/v1/tests/get_handler_test.go

@@ -85,17 +85,15 @@ func TestV1GetKeyDir(t *testing.T) {
 //
 //
 func TestV1WatchKey(t *testing.T) {
 func TestV1WatchKey(t *testing.T) {
 	tests.RunServer(func(s *server.Server) {
 	tests.RunServer(func(s *server.Server) {
-		var body map[string]interface{}
+		var watchResp *http.Response
 		c := make(chan bool)
 		c := make(chan bool)
 		go func() {
 		go func() {
-			resp, _ := tests.Get(fmt.Sprintf("%s%s", s.URL(), "/v1/watch/foo/bar"))
-			body = tests.ReadBodyJSON(resp)
+			watchResp, _ = tests.Get(fmt.Sprintf("%s%s", s.URL(), "/v1/watch/foo/bar"))
 			c <- true
 			c <- true
 		}()
 		}()
 
 
 		// Make sure response didn't fire early.
 		// Make sure response didn't fire early.
 		time.Sleep(1 * time.Millisecond)
 		time.Sleep(1 * time.Millisecond)
-		assert.Nil(t, body, "")
 
 
 		// Set a value.
 		// Set a value.
 		v := url.Values{}
 		v := url.Values{}
@@ -113,6 +111,7 @@ func TestV1WatchKey(t *testing.T) {
 			t.Fatal("cannot get watch result")
 			t.Fatal("cannot get watch result")
 		}
 		}
 
 
+		body := tests.ReadBodyJSON(watchResp)
 		assert.NotNil(t, body, "")
 		assert.NotNil(t, body, "")
 		assert.Equal(t, body["action"], "set", "")
 		assert.Equal(t, body["action"], "set", "")
 
 

+ 3 - 4
server/v2/tests/get_handler_test.go

@@ -90,17 +90,15 @@ func TestV2GetKeyRecursively(t *testing.T) {
 //
 //
 func TestV2WatchKey(t *testing.T) {
 func TestV2WatchKey(t *testing.T) {
 	tests.RunServer(func(s *server.Server) {
 	tests.RunServer(func(s *server.Server) {
-		var body map[string]interface{}
+		var watchResp *http.Response
 		c := make(chan bool)
 		c := make(chan bool)
 		go func() {
 		go func() {
-			resp, _ := tests.Get(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar?wait=true"))
-			body = tests.ReadBodyJSON(resp)
+			watchResp, _ = tests.Get(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar?wait=true"))
 			c <- true
 			c <- true
 		}()
 		}()
 
 
 		// Make sure response didn't fire early.
 		// Make sure response didn't fire early.
 		time.Sleep(1 * time.Millisecond)
 		time.Sleep(1 * time.Millisecond)
-		assert.Nil(t, body, "")
 
 
 		// Set a value.
 		// Set a value.
 		v := url.Values{}
 		v := url.Values{}
@@ -118,6 +116,7 @@ func TestV2WatchKey(t *testing.T) {
 			t.Fatal("cannot get watch result")
 			t.Fatal("cannot get watch result")
 		}
 		}
 
 
+		body := tests.ReadBodyJSON(watchResp)
 		assert.NotNil(t, body, "")
 		assert.NotNil(t, body, "")
 		assert.Equal(t, body["action"], "set", "")
 		assert.Equal(t, body["action"], "set", "")