Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clientv3/integration: add TestBalancerUnderNetworkPartitionWatch #8762

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions clientv3/integration/network_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,69 @@ func testBalancerUnderNetworkPartition(t *testing.T, op func(*clientv3.Client, c
t.Errorf("balancer did not switch in time (%v)", err)
}
}

func TestBalancerUnderNetworkPartitionWatchLeader(t *testing.T) {
testBalancerUnderNetworkPartitionWatch(t, true)
}

func TestBalancerUnderNetworkPartitionWatchFollower(t *testing.T) {
testBalancerUnderNetworkPartitionWatch(t, false)
}

// testBalancerUnderNetworkPartitionWatch ensures watch stream
// to a partitioned node be closed when context requires leader.
func testBalancerUnderNetworkPartitionWatch(t *testing.T, isolateLeader bool) {
defer testutil.AfterTest(t)

clus := integration.NewClusterV3(t, &integration.ClusterConfig{
Size: 3,
SkipCreatingClient: true,
})
defer clus.Terminate(t)

eps := []string{clus.Members[0].GRPCAddr(), clus.Members[1].GRPCAddr(), clus.Members[2].GRPCAddr()}

target := clus.WaitLeader(t)
if !isolateLeader {
target = (target + 1) % 3
}

// pin eps[target]
watchCli, err := clientv3.New(clientv3.Config{Endpoints: []string{eps[target]}})
if err != nil {
t.Fatal(err)
}
defer watchCli.Close()

// wait for eps[target] to be pinned
waitPinReady(t, watchCli)

// add all eps to list, so that when the original pined one fails
// the client can switch to other available eps
watchCli.SetEndpoints(eps...)

wch := watchCli.Watch(clientv3.WithRequireLeader(context.Background()), "foo", clientv3.WithCreatedNotify())
select {
case <-wch:
case <-time.After(3 * time.Second):
t.Fatal("took too long to create watch")
}

// isolate eps[target]
clus.Members[target].InjectPartition(t,
clus.Members[(target+1)%3],
clus.Members[(target+2)%3],
)

select {
case ev := <-wch:
if len(ev.Events) != 0 {
t.Fatal("expected no event")
}
if err = ev.Err(); err != rpctypes.ErrNoLeader {
t.Fatalf("expected %v, got %v", rpctypes.ErrNoLeader, err)
}
case <-time.After(3 * time.Second): // enough time to detect leader lost
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our integration tests are starting to get filled with hard coded wait times that we believe are appropriate for various cases.

To help maintain the tests and keep flakiness to a minimum, should we establish a set of constants that we references from the integration tests instead? E.g instead of 3 here, maybe have a constant like maxLeaderChangeWait. Once we have a reasonable set of constants, then developers don't need to try to figure out what a good number of seconds is each time they write a test, and if we determine we need to increase the number to minimize test flakes based, we can change it in one place...

Just a though, we don't need to do this now. If this seams reasonable, maybe create an issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should. these random in place non-const timeouts def is not helping anything at all. and we are simply waiting for flakes.

t.Fatal("took too long to detect leader lost")
}
}