Skip to content

Commit c3ade98

Browse files
authored
Fix more flaky tests in TestClusterJoinAndReconnect (#4701)
As explained in more detail in commit `88b4e13d09975b61290493f8893bb4fb7796a93f`, the tests in `cluster_test.go` will occasionally fail. The underlying reason for the failure is that the test only waits for `p2` to be ready, but this does not reflect whether `p1` has updated its memberlist. However, that commit only fixed the test `TestJoinLeave`. I have now ran the other tests in `cluster_test.go` 2400 times, and identified the following problematic tests: `TestSetPeerNames` and `TestTLSConnection`. Since the underlying faulty code is mostly identical, so is the corresponding fix. Signed-off-by: Solomon Jacobs <[email protected]>
1 parent 6ceb38d commit c3ade98

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cluster/cluster_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ func testTLSConnection(t *testing.T) {
348348
p2.WaitReady(context.Background())
349349
require.Equal(t, "ready", p2.Status())
350350

351-
require.Equal(t, 2, p1.ClusterSize())
351+
require.Eventually(t, func() bool { return p1.ClusterSize() == 2 }, 5*time.Second, time.Second)
352352
p2.Leave(0 * time.Second)
353-
require.Equal(t, 1, p1.ClusterSize())
353+
require.Eventually(t, func() bool { return p1.ClusterSize() == 1 }, 5*time.Second, time.Second)
354354
require.Len(t, p1.failedPeers, 1)
355355
require.Equal(t, p2.Self().Address(), p1.peers[p2.Self().Address()].Address())
356356
require.Equal(t, p2.Name(), p1.failedPeers[0].Name)
@@ -423,8 +423,8 @@ func testPeerNames(t *testing.T, name1, name2 string) {
423423
require.NoError(t, p2.WaitReady(context.Background()))
424424

425425
if name1 != name2 {
426-
require.Equal(t, 2, p1.ClusterSize())
427-
require.Equal(t, 2, p2.ClusterSize())
426+
require.Eventually(t, func() bool { return p1.ClusterSize() == 2 }, 5*time.Second, time.Second)
427+
require.Eventually(t, func() bool { return p2.ClusterSize() == 2 }, 5*time.Second, time.Second)
428428
require.NotEqual(t, p1.Name(), p2.Name(), "peers should have different names")
429429
}
430430
}

0 commit comments

Comments
 (0)