Skip to content

Commit

Permalink
Fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Oct 13, 2020
1 parent 533f033 commit 5675e28
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions workerpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,21 @@ func TestOverflow(t *testing.T) {
}

func TestStopRace(t *testing.T) {
wp := New(20)
wp := New(max)
workRelChan := make(chan struct{})

// Start and pause all workers.
ctx, cancel := context.WithCancel(context.Background())
wp.Pause(ctx)
var started sync.WaitGroup
started.Add(max)

// Start workers, and have them all wait on a channel before completing.
for i := 0; i < max; i++ {
wp.Submit(func() {
started.Done()
<-workRelChan
})
}

started.Wait()

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

cancel()
close(workRelChan)

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

0 comments on commit 5675e28

Please sign in to comment.