Skip to content

Commit d891a5f

Browse files
committed
allocator: fix flake in TestWatchRemoteKVStore
The TestWatchRemoteKVStore test is currently affected by a potential source of flakiness because it directly asserts that the cache is synchronized after validating that it has been registered. However, the two operations are performed independently, and the on-sync callback handler is invoked after having released the lock, which implies that it may not have been invoked at check time. Let's get this fixed by wrapping the check with Eventually. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
1 parent 03d1726 commit d891a5f

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

pkg/allocator/allocator_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,11 @@ func TestWatchRemoteKVStore(t *testing.T) {
584584
return global.remoteCaches["remote"] == rc
585585
}, 1*time.Second, 10*time.Millisecond)
586586

587-
require.True(t, rc.Synced(), "The cache should now be synchronized")
588-
require.True(t, synced.Load(), "The on-sync callback should have been executed")
587+
require.EventuallyWithT(t, func(c *assert.CollectT) {
588+
assert.True(c, rc.Synced(), "The cache should now be synchronized")
589+
assert.True(c, synced.Load(), "The on-sync callback should have been executed")
590+
}, 1*time.Second, 10*time.Millisecond)
591+
589592
stop(cancel)
590593
require.False(t, rc.Synced(), "The cache should no longer be synchronized when stopped")
591594

0 commit comments

Comments
 (0)