Skip to content

Commit f08bd7c

Browse files
committed
fix flaky unit test
1 parent 5bcc55b commit f08bd7c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

internal/worker/concurrency.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func (p *permit) AcquireChan(ctx context.Context, wg *sync.WaitGroup) <-chan str
6969
wg.Add(1)
7070
go func() {
7171
defer wg.Done()
72-
defer close(ch) // close channel when permit is acquired or expired
7372
if err := p.sem.Acquire(ctx, 1); err != nil {
7473
return
7574
}

internal/worker/concurrency_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestPermit_Simulation(t *testing.T) {
4444
}{
4545
{
4646
name: "enough permit, no blocking",
47-
maxTestDuration: 200 * time.Millisecond,
47+
maxTestDuration: 100 * time.Millisecond,
4848
capacity: []int{1000},
4949
goroutines: 100,
5050
goroutinesAcquireChan: 100,
@@ -60,23 +60,23 @@ func TestPermit_Simulation(t *testing.T) {
6060
},
6161
{
6262
name: "not enough permit for some to acquire, fail some",
63-
maxTestDuration: 100 * time.Millisecond,
63+
maxTestDuration: 300 * time.Millisecond,
6464
capacity: []int{100},
6565
goroutines: 500,
6666
goroutinesAcquireChan: 500,
6767
expectFailuresAtLeast: 1,
6868
},
6969
{
7070
name: "not enough permit at beginning but due to capacity change, blocking but all acquire",
71-
maxTestDuration: 100 * time.Second,
72-
capacity: []int{100, 200, 300},
71+
maxTestDuration: 300 * time.Millisecond,
72+
capacity: []int{100, 300, 500},
7373
goroutines: 500,
7474
goroutinesAcquireChan: 500,
7575
expectFailures: 0,
7676
},
7777
{
7878
name: "not enough permit for any acquire, fail all",
79-
maxTestDuration: 1 * time.Second,
79+
maxTestDuration: 300 * time.Millisecond,
8080
capacity: []int{0},
8181
goroutines: 1000,
8282
expectFailures: 1000,

0 commit comments

Comments
 (0)