Skip to content

Commit e2470f0

Browse files
committed
chore(taskgroup): add test to verify waiting tasks counter
1 parent e2fee68 commit e2470f0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

group_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,35 @@ func TestTaskGroupMetricsWithCancelledContext(t *testing.T) {
382382
assert.Equal(t, uint64(5), pool.SuccessfulTasks())
383383
assert.Equal(t, uint64(5), pool.FailedTasks())
384384
}
385+
386+
func TestTaskGroupWaitingTasks(t *testing.T) {
387+
// Create a pool with limited concurrency
388+
pool := NewPool(10)
389+
390+
// Create a task group
391+
group := pool.NewGroup()
392+
393+
start := make(chan struct{})
394+
end := make(chan struct{})
395+
396+
// Submit 20 tasks
397+
for i := 0; i < 20; i++ {
398+
group.Submit(func() {
399+
<-start
400+
<-end
401+
})
402+
}
403+
404+
// Start half of the tasks
405+
for i := 0; i < 10; i++ {
406+
start <- struct{}{}
407+
}
408+
409+
assert.Equal(t, int64(10), pool.RunningWorkers())
410+
assert.Equal(t, uint64(10), pool.WaitingTasks())
411+
412+
// Wait for all tasks to complete
413+
close(start)
414+
close(end)
415+
group.Wait()
416+
}

0 commit comments

Comments
 (0)