Browse Source

clientv3/integration: WaitLeader to follower

Fix https://github.com/coreos/etcd/issues/5601.
Gyu-Ho Lee 9 years ago
parent
commit
753073198f
1 changed files with 9 additions and 5 deletions
  1. 9 5
      clientv3/integration/kv_test.go

+ 9 - 5
clientv3/integration/kv_test.go

@@ -527,18 +527,22 @@ func TestKVCompact(t *testing.T) {
 func TestKVGetRetry(t *testing.T) {
 func TestKVGetRetry(t *testing.T) {
 	defer testutil.AfterTest(t)
 	defer testutil.AfterTest(t)
 
 
-	clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 3})
+	clusterSize := 3
+	clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: clusterSize})
 	defer clus.Terminate(t)
 	defer clus.Terminate(t)
 
 
-	kv := clientv3.NewKV(clus.Client(0))
+	// because killing leader and following election
+	// could give no other endpoints for client reconnection
+	fIdx := (clus.WaitLeader(t) + 1) % clusterSize
+
+	kv := clientv3.NewKV(clus.Client(fIdx))
 	ctx := context.TODO()
 	ctx := context.TODO()
 
 
 	if _, err := kv.Put(ctx, "foo", "bar"); err != nil {
 	if _, err := kv.Put(ctx, "foo", "bar"); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	clus.Members[0].Stop(t)
-	<-clus.Members[0].StopNotify()
+	clus.Members[fIdx].Stop(t)
 
 
 	donec := make(chan struct{})
 	donec := make(chan struct{})
 	go func() {
 	go func() {
@@ -563,7 +567,7 @@ func TestKVGetRetry(t *testing.T) {
 	}()
 	}()
 
 
 	time.Sleep(100 * time.Millisecond)
 	time.Sleep(100 * time.Millisecond)
-	clus.Members[0].Restart(t)
+	clus.Members[fIdx].Restart(t)
 
 
 	select {
 	select {
 	case <-time.After(5 * time.Second):
 	case <-time.After(5 * time.Second):