From 0f066be2953aa40b9594a80358f043c9ce2ce141 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 17 Oct 2024 07:22:36 -0500 Subject: [PATCH] core/utils: fix TestThreadControl_GoCtx flake (#14819) --- core/utils/thread_control_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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()) }