Skip to content

Commit 5675e28

Browse files
committed
Fix broken test
1 parent 533f033 commit 5675e28

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

workerpool_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,21 @@ func TestOverflow(t *testing.T) {
311311
}
312312

313313
func TestStopRace(t *testing.T) {
314-
wp := New(20)
314+
wp := New(max)
315+
workRelChan := make(chan struct{})
315316

316-
// Start and pause all workers.
317-
ctx, cancel := context.WithCancel(context.Background())
318-
wp.Pause(ctx)
317+
var started sync.WaitGroup
318+
started.Add(max)
319+
320+
// Start workers, and have them all wait on a channel before completing.
321+
for i := 0; i < max; i++ {
322+
wp.Submit(func() {
323+
started.Done()
324+
<-workRelChan
325+
})
326+
}
327+
328+
started.Wait()
319329

320330
const doneCallers = 5
321331
stopDone := make(chan struct{}, doneCallers)
@@ -332,7 +342,7 @@ func TestStopRace(t *testing.T) {
332342
default:
333343
}
334344

335-
cancel()
345+
close(workRelChan)
336346

337347
timeout := time.After(time.Second)
338348
for i := 0; i < doneCallers; i++ {

0 commit comments

Comments
 (0)