Skip to content

Commit 0f07151

Browse files
authored
Fix Ring/Memberlist Join Test Flakiness (#5992)
The tests rely on the CPU's wall clock which can be unreliable if there is CPU starvation. If we give the tests enough time to run, they are more much more reliable and resilient to CPU starvation. Signed-off-by: Charlie Le <[email protected]>
1 parent 60f24cf commit 0f07151

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pkg/ring/kv/memberlist/memberlist_client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ func TestMemberlistJoinOnStarting(t *testing.T) {
827827
return mkv2.memberlist.NumMembers()
828828
}
829829

830-
poll(t, 5*time.Second, 2, membersFunc)
830+
poll(t, 1*time.Minute, 2, membersFunc)
831831
}
832832

833833
func getFreePorts(count int) ([]int, error) {
@@ -1103,20 +1103,20 @@ func TestRejoin(t *testing.T) {
11031103
return mkv2.memberlist.NumMembers()
11041104
}
11051105

1106-
poll(t, 5*time.Second, 2, membersFunc)
1106+
poll(t, 1*time.Minute, 2, membersFunc)
11071107

11081108
// Shutdown first KV
11091109
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), mkv1))
11101110

11111111
// Second KV should see single member now.
1112-
poll(t, 5*time.Second, 1, membersFunc)
1112+
poll(t, 1*time.Minute, 1, membersFunc)
11131113

11141114
// Let's start first KV again. It is not configured to join the cluster, but KV2 is rejoining.
11151115
mkv1 = NewKV(cfg1, log.NewNopLogger(), &dnsProviderMock{}, prometheus.NewPedanticRegistry())
11161116
require.NoError(t, services.StartAndAwaitRunning(context.Background(), mkv1))
11171117
defer services.StopAndAwaitTerminated(context.Background(), mkv1) //nolint:errcheck
11181118

1119-
poll(t, 5*time.Second, 2, membersFunc)
1119+
poll(t, 1*time.Minute, 2, membersFunc)
11201120
}
11211121

11221122
func TestMessageBuffer(t *testing.T) {

pkg/ring/lifecycler_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,17 +494,17 @@ func TestCheckReady_CheckRingHealth(t *testing.T) {
494494
}{
495495
"should wait until the self instance is ACTIVE and healthy in the ring when 'check ring health' is disabled": {
496496
checkRingHealthEnabled: false,
497-
firstJoinAfter: time.Second,
498-
secondJoinAfter: 3 * time.Second,
499-
expectedFirstMinReady: time.Second,
500-
expectedFirstMaxReady: 2 * time.Second,
497+
firstJoinAfter: 1000 * time.Millisecond,
498+
secondJoinAfter: 3000 * time.Millisecond,
499+
expectedFirstMinReady: 900 * time.Millisecond,
500+
expectedFirstMaxReady: 1900 * time.Millisecond,
501501
},
502502
"should wait until all instances are ACTIVE and healthy in the ring when 'check ring health' is enabled": {
503503
checkRingHealthEnabled: true,
504-
firstJoinAfter: time.Second,
505-
secondJoinAfter: 3 * time.Second,
506-
expectedFirstMinReady: 3 * time.Second,
507-
expectedFirstMaxReady: 4 * time.Second,
504+
firstJoinAfter: 1000 * time.Millisecond,
505+
secondJoinAfter: 3000 * time.Millisecond,
506+
expectedFirstMinReady: 2900 * time.Millisecond,
507+
expectedFirstMaxReady: 3900 * time.Millisecond,
508508
},
509509
}
510510

0 commit comments

Comments
 (0)