Browse Source

client/integration: try to fix tests

nolouch 7 years ago
parent
commit
6ea54195a6

+ 5 - 5
clientv3/integration/kv_test.go

@@ -439,6 +439,11 @@ func TestKVGetErrConnClosed(t *testing.T) {
 	cli := clus.Client(0)
 	cli := clus.Client(0)
 
 
 	donec := make(chan struct{})
 	donec := make(chan struct{})
+	if err := cli.Close(); err != nil {
+		t.Fatal(err)
+	}
+	clus.TakeClient(0)
+
 	go func() {
 	go func() {
 		defer close(donec)
 		defer close(donec)
 		_, err := cli.Get(context.TODO(), "foo")
 		_, err := cli.Get(context.TODO(), "foo")
@@ -447,11 +452,6 @@ func TestKVGetErrConnClosed(t *testing.T) {
 		}
 		}
 	}()
 	}()
 
 
-	if err := cli.Close(); err != nil {
-		t.Fatal(err)
-	}
-	clus.TakeClient(0)
-
 	select {
 	select {
 	case <-time.After(integration.RequestWaitTimeout):
 	case <-time.After(integration.RequestWaitTimeout):
 		t.Fatal("kv.Get took too long")
 		t.Fatal("kv.Get took too long")

+ 3 - 4
clientv3/integration/lease_test.go

@@ -291,6 +291,9 @@ func TestLeaseGrantErrConnClosed(t *testing.T) {
 
 
 	cli := clus.Client(0)
 	cli := clus.Client(0)
 	clus.TakeClient(0)
 	clus.TakeClient(0)
+	if err := cli.Close(); err != nil {
+		t.Fatal(err)
+	}
 
 
 	donec := make(chan struct{})
 	donec := make(chan struct{})
 	go func() {
 	go func() {
@@ -303,10 +306,6 @@ func TestLeaseGrantErrConnClosed(t *testing.T) {
 		}
 		}
 	}()
 	}()
 
 
-	if err := cli.Close(); err != nil {
-		t.Fatal(err)
-	}
-
 	select {
 	select {
 	case <-time.After(integration.RequestWaitTimeout):
 	case <-time.After(integration.RequestWaitTimeout):
 		t.Fatal("le.Grant took too long")
 		t.Fatal("le.Grant took too long")

+ 1 - 1
clientv3/integration/network_partition_test.go

@@ -310,7 +310,7 @@ func TestDropReadUnderNetworkPartition(t *testing.T) {
 		t.Fatalf("expected %v, got %v", rpctypes.ErrLeaderChanged, err)
 		t.Fatalf("expected %v, got %v", rpctypes.ErrLeaderChanged, err)
 	}
 	}
 
 
-	ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
+	ctx, cancel = context.WithTimeout(context.TODO(), 10*time.Second)
 	_, err = kvc.Get(ctx, "a")
 	_, err = kvc.Get(ctx, "a")
 	cancel()
 	cancel()
 	if err != nil {
 	if err != nil {

+ 1 - 1
etcdserver/server.go

@@ -946,8 +946,8 @@ func (s *EtcdServer) run() {
 				s.leaderChangedMu.Lock()
 				s.leaderChangedMu.Lock()
 				lc := s.leaderChanged
 				lc := s.leaderChanged
 				s.leaderChanged = make(chan struct{})
 				s.leaderChanged = make(chan struct{})
-				s.leaderChangedMu.Unlock()
 				close(lc)
 				close(lc)
+				s.leaderChangedMu.Unlock()
 			}
 			}
 			// TODO: remove the nil checking
 			// TODO: remove the nil checking
 			// current test utility does not provide the stats
 			// current test utility does not provide the stats

+ 1 - 4
integration/v3_lease_test.go

@@ -565,14 +565,11 @@ func TestV3LeaseFailover(t *testing.T) {
 	md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, rpctypes.MetadataHasLeader)
 	md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, rpctypes.MetadataHasLeader)
 	mctx := metadata.NewOutgoingContext(context.Background(), md)
 	mctx := metadata.NewOutgoingContext(context.Background(), md)
 	ctx, cancel := context.WithCancel(mctx)
 	ctx, cancel := context.WithCancel(mctx)
+	defer cancel()
 	lac, err := lc.LeaseKeepAlive(ctx)
 	lac, err := lc.LeaseKeepAlive(ctx)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
-	defer func() {
-		lac.CloseSend()
-		cancel()
-	}()
 
 
 	// send keep alive to old leader until the old leader starts
 	// send keep alive to old leader until the old leader starts
 	// to drop lease request.
 	// to drop lease request.