Skip to content

Commit

Permalink
fix(tests): fix flaky test (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchenggit authored Dec 2, 2024
1 parent 9f55161 commit b0eb1b8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,22 @@ func TestShutdown(t *testing.T) {
}

func TestGracefulShutdown(t *testing.T) {
var counter int64
atomic.StoreInt64(&counter, 0)
var counter atomic.Int64

pool := NewPool(100, 100)

wait := sync.WaitGroup{}
wait.Add(100)
for i := 0; i < 100; i++ {
err := pool.SubmitFn(time.Second, func() {
wait.Done()
time.Sleep(time.Second)
atomic.AddInt64(&counter, 1)
counter.Add(1)
})
assert.NoError(t, err)
}
wait.Wait() // wait for all tasks to be scheduled

pool.Shutdown()
assert.EqualValues(t, 100, counter) // all submitted and scheduled tasks should be executed successfully
assert.EqualValues(t, 100, counter.Load()) // all submitted and scheduled tasks should be executed successfully
}

0 comments on commit b0eb1b8

Please sign in to comment.