diff --git a/core/utils/thread_control_test.go b/core/utils/thread_control_test.go index 49bec742428..9b26c7ae8e0 100644 --- a/core/utils/thread_control_test.go +++ b/core/utils/thread_control_test.go @@ -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) @@ -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()) }