Skip to content

Commit 40be3e6

Browse files
committed
statedb: Fix flake in TestWatchSet
time.Now was called after the context with timeout was created leading to the test sometimes failing. Signed-off-by: Jussi Maki <jussi.maki@isovalent.com>
1 parent 77960fe commit 40be3e6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

watchset_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ func TestWatchSet(t *testing.T) {
3737
require.ErrorIs(t, err, context.Canceled)
3838
require.Empty(t, chs)
3939

40-
// Few channels, timed out context. With tiny 'settleTime' we wait for the context to cancel.
40+
// Few channels, timed out context.
4141
duration := 10 * time.Millisecond
42-
ctx, cancel = context.WithTimeout(context.Background(), duration)
4342
t0 := time.Now()
43+
ctx, cancel = context.WithTimeout(context.Background(), duration)
44+
45+
// Wait with a settle time of 1ns. Since settle time only comes to play
46+
// after at least one channel has closed this will block until [ctx]
47+
// cancels (e.g. for [duration]).
4448
chs, err = ws.Wait(ctx, time.Nanosecond)
4549
require.ErrorIs(t, err, context.DeadlineExceeded)
4650
require.Empty(t, chs)
47-
require.True(t, time.Since(t0) > duration, "expected to wait until context cancels")
51+
require.Greater(t, time.Since(t0), duration, "expected to wait until context times out")
4852
cancel()
4953

5054
// One closed channel. Should wait until 'settleTime' expires.

0 commit comments

Comments
 (0)