Skip to content

Commit

Permalink
core/utils: fix TestThreadControl_GoCtx flake (#14819)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Oct 17, 2024
1 parent 3cbc3a4 commit 0f066be
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/utils/thread_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func TestThreadControl_GoCtx(t *testing.T) {
var wg sync.WaitGroup
finished := atomic.Int32{}

timeout := 10 * time.Millisecond
timeout := 100 * time.Millisecond

ctx, cancel := context.WithTimeout(context.Background(), timeout)
start := time.Now()
ctx, cancel := context.WithDeadline(context.Background(), start.Add(timeout))
defer cancel()

wg.Add(1)
Expand All @@ -48,10 +49,9 @@ func TestThreadControl_GoCtx(t *testing.T) {
finished.Add(1)
})

start := time.Now()
wg.Wait()
end := time.Since(start)
assert.Greater(t, end, timeout-1)
assert.Less(t, end, 2*timeout)
elapsed := time.Since(start)
assert.GreaterOrEqual(t, elapsed, timeout)
assert.Less(t, elapsed, 2*timeout)
require.Equal(t, int32(1), finished.Load())
}

0 comments on commit 0f066be

Please sign in to comment.