diff --git a/utils/rate_test.go b/utils/rate_test.go index 961234c00..c4a5dca39 100644 --- a/utils/rate_test.go +++ b/utils/rate_test.go @@ -270,7 +270,6 @@ func (r *runnerImpl) goWait(fn func()) { } func TestRateLimiter(t *testing.T) { - t.Parallel() runTest(t, func(r testRunner) { rl := r.createLimiter(100, WithoutSlack) @@ -288,7 +287,6 @@ func TestRateLimiter(t *testing.T) { func TestDelayedRateLimiter(t *testing.T) { t.Skip(UnstableTest) - t.Parallel() runTest(t, func(r testRunner) { slow := r.createLimiter(10, WithoutSlack) fast := r.createLimiter(100, WithoutSlack) @@ -307,7 +305,6 @@ func TestDelayedRateLimiter(t *testing.T) { } func TestPer(t *testing.T) { - t.Parallel() runTest(t, func(r testRunner) { rl := r.createLimiter(7, WithoutSlack, Per(time.Minute)) @@ -322,7 +319,6 @@ func TestPer(t *testing.T) { // TestInitial verifies that the initial sequence is scheduled as expected. func TestInitial(t *testing.T) { - t.Parallel() tests := []struct { msg string opts []Option @@ -339,27 +335,25 @@ func TestInitial(t *testing.T) { for _, tt := range tests { t.Run(tt.msg, func(t *testing.T) { runTest(t, func(r testRunner) { + perRequest := 100 * time.Millisecond rl := r.createLimiter(10, tt.opts...) var ( clk = r.getClock() prev = clk.Now() - results = make(chan time.Time) + results = make(chan time.Time, 3) have []time.Duration - startWg sync.WaitGroup ) - startWg.Add(3) - for i := 0; i < 3; i++ { - go func() { - startWg.Done() - results <- rl.Take() - }() - } + results <- rl.Take() + clk.Add(perRequest) + + results <- rl.Take() + clk.Add(perRequest) - startWg.Wait() - clk.Add(time.Second) + results <- rl.Take() + clk.Add(perRequest) for i := 0; i < 3; i++ { ts := <-results @@ -370,8 +364,8 @@ func TestInitial(t *testing.T) { assert.Equal(t, []time.Duration{ 0, - time.Millisecond * 100, - time.Millisecond * 100, + perRequest, + perRequest, }, have, "bad timestamps for inital takes", @@ -382,7 +376,6 @@ func TestInitial(t *testing.T) { } func TestMaxSlack(t *testing.T) { - t.Parallel() runTest(t, func(r testRunner) { rl := r.createLimiter(1, WithSlack(1)) @@ -398,7 +391,6 @@ func TestMaxSlack(t *testing.T) { } func TestSlack(t *testing.T) { - t.Parallel() // To simulate slack, we combine two limiters. // - First, we start a single goroutine with both of them, // during this time the slow limiter will dominate,