diff --git a/pkg/util/worker_pool_test.go b/pkg/util/worker_pool_test.go index 037a9ef61a..050981a7e3 100644 --- a/pkg/util/worker_pool_test.go +++ b/pkg/util/worker_pool_test.go @@ -32,11 +32,19 @@ func TestWorkerPool_TestMetric(t *testing.T) { wg := &sync.WaitGroup{} wg.Add(1) + // Use a channel to signal that the first job has started executing. + started := make(chan struct{}) + // Block the first job workerPool.Submit(func() { + close(started) wg.Wait() }) + // Wait for the first job to actually start running on the worker, + // ensuring the worker is busy before we submit the next job. + <-started + // create an extra job to increment the metric workerPool.Submit(func() {}) require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`