Browse Source

integration: don't expect recv to stop on CloseSend in waitResponse

Anthony Romano 9 years ago
parent
commit
6d9168a2ec
1 changed files with 8 additions and 6 deletions
  1. 8 6
      integration/v3_watch_test.go

+ 8 - 6
integration/v3_watch_test.go

@@ -948,21 +948,23 @@ func testV3WatchMultipleStreams(t *testing.T, startRev int64) {
 // returned closing the WatchClient stream. Or the response will
 // returned closing the WatchClient stream. Or the response will
 // be returned.
 // be returned.
 func waitResponse(wc pb.Watch_WatchClient, timeout time.Duration) (bool, *pb.WatchResponse) {
 func waitResponse(wc pb.Watch_WatchClient, timeout time.Duration) (bool, *pb.WatchResponse) {
-	rCh := make(chan *pb.WatchResponse)
+	rCh := make(chan *pb.WatchResponse, 1)
+	donec := make(chan struct{})
+	defer close(donec)
 	go func() {
 	go func() {
 		resp, _ := wc.Recv()
 		resp, _ := wc.Recv()
-		rCh <- resp
+		select {
+		case rCh <- resp:
+		case <-donec:
+		}
 	}()
 	}()
 	select {
 	select {
 	case nr := <-rCh:
 	case nr := <-rCh:
 		return false, nr
 		return false, nr
 	case <-time.After(timeout):
 	case <-time.After(timeout):
 	}
 	}
+	// didn't get response
 	wc.CloseSend()
 	wc.CloseSend()
-	rv, ok := <-rCh
-	if rv != nil || !ok {
-		return false, rv
-	}
 	return true, nil
 	return true, nil
 }
 }