Browse Source

clientv3: wait for Get goroutine in TestDialCancel

Anthony Romano 8 years ago
parent
commit
d1a9ccb2b9
1 changed files with 12 additions and 1 deletions
  1. 12 1
      clientv3/client_test.go

+ 12 - 1
clientv3/client_test.go

@@ -49,7 +49,13 @@ func TestDialCancel(t *testing.T) {
 	c.SetEndpoints("http://254.0.0.1:12345")
 
 	// issue Get to force redial attempts
-	go c.Get(context.TODO(), "abc")
+	getc := make(chan struct{})
+	go func() {
+		defer close(getc)
+		// Get may hang forever on grpc's Stream.Header() if its
+		// context is never canceled.
+		c.Get(c.Ctx(), "abc")
+	}()
 
 	// wait a little bit so client close is after dial starts
 	time.Sleep(100 * time.Millisecond)
@@ -65,6 +71,11 @@ func TestDialCancel(t *testing.T) {
 		t.Fatalf("failed to close")
 	case <-donec:
 	}
+	select {
+	case <-time.After(5 * time.Second):
+		t.Fatalf("get failed to exit")
+	case <-getc:
+	}
 }
 
 func TestDialTimeout(t *testing.T) {