Skip to content

Commit

Permalink
fix unit test bug
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Jin <[email protected]>
  • Loading branch information
jnyi committed Apr 9, 2024
1 parent b4e53ee commit a5f8b31
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/pool/worker_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package pool

import (
"sync"
"sync/atomic"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -14,6 +13,7 @@ import (
func TestGo(t *testing.T) {
var expectedWorksDone uint32
var workerPoolSize uint
var mu sync.Mutex
workerPoolSize = 5
p := NewWorkerPool(workerPoolSize)
p.Init()
Expand All @@ -23,7 +23,9 @@ func TestGo(t *testing.T) {
for i := 0; i < int(workerPoolSize*3); i++ {
wg.Add(1)
p.Go(func() {
atomic.AddUint32(&expectedWorksDone, 1)
mu.Lock()
defer mu.Unlock()
expectedWorksDone++
wg.Done()
})
}
Expand Down

0 comments on commit a5f8b31

Please sign in to comment.