From a982594a4960416b9aebbf959f6ce9720d6e2bbd Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Fri, 4 Oct 2024 15:14:06 -0400 Subject: [PATCH] Get rid of `baseGoroutines`. It's now zero --- concurrency/worker_test.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/concurrency/worker_test.go b/concurrency/worker_test.go index 4be57e554..338062055 100644 --- a/concurrency/worker_test.go +++ b/concurrency/worker_test.go @@ -24,40 +24,38 @@ func TestReusableGoroutinesPool(t *testing.T) { return strings.Count(string(buf), " in goroutine "+string(testGoroutine)) } - baseGoroutines := countGoroutines() - const workers = 2 - w := NewReusableGoroutinesPool(workers) - - require.Equal(t, baseGoroutines+workers, countGoroutines()) + const workerCount = 2 + w := NewReusableGoroutinesPool(workerCount) + require.Equal(t, workerCount, countGoroutines()) // Wait a little bit so both goroutines would be waiting on the jobs chan. time.Sleep(10 * time.Millisecond) ch := make(chan struct{}) w.Go(func() { <-ch }) - require.Equal(t, baseGoroutines+workers, countGoroutines()) + require.Equal(t, workerCount, countGoroutines()) w.Go(func() { <-ch }) - require.Equal(t, baseGoroutines+workers, countGoroutines()) + require.Equal(t, workerCount, countGoroutines()) w.Go(func() { <-ch }) - require.Equal(t, baseGoroutines+workers+1, countGoroutines()) + require.Equal(t, workerCount+1, countGoroutines()) // end workloads, we should have only the workers again. close(ch) for i := 0; i < 1000; i++ { - if countGoroutines() == baseGoroutines+workers { + if countGoroutines() == workerCount { break } time.Sleep(time.Millisecond) } - require.Equal(t, baseGoroutines+workers, countGoroutines()) + require.Equal(t, workerCount, countGoroutines()) // close the workers, eventually they should be gone. w.Close() for i := 0; i < 1000; i++ { - if countGoroutines() == baseGoroutines { + if countGoroutines() == 0 { return } time.Sleep(time.Millisecond) } - t.Fatalf("expected %d goroutines after closing, got %d", baseGoroutines, countGoroutines()) + t.Fatalf("expected %d goroutines after closing, got %d", 0, countGoroutines()) }