Skip to content

Commit c6a8275

Browse files
authored
fix(ha): Fix flaky TestWatchPrefixNilPanicWithMemberlist (#7493)
1 parent 5f643d5 commit c6a8275

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

pkg/ha/ha_tracker_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,16 @@ func TestWatchPrefixNilPanicWithMemberlist(t *testing.T) {
265265
replica := "replica0"
266266
key := userID + "/" + cluster
267267

268+
// Give the WatchPrefix goroutine in loop() time to register its watcher
269+
// channel in the memberlist KV before we write. Without this, the CAS
270+
// notification can fire before the watcher is registered, causing the
271+
// key to never appear in the elected cache.
272+
time.Sleep(100 * time.Millisecond)
273+
268274
now := time.Now()
269275
require.NoError(t, tracker.CheckReplica(ctx, userID, cluster, replica, now))
270276

271-
test.Poll(t, 3*time.Second, nil, func() any {
277+
test.Poll(t, 5*time.Second, nil, func() any {
272278
tracker.electedLock.RLock()
273279
defer tracker.electedLock.RUnlock()
274280
if _, ok := tracker.elected[key]; !ok {

0 commit comments

Comments
 (0)