Skip to content

Commit

Permalink
Merge pull request #206 from AwesomePatrol/fix-ticker-rate-limiter-test
Browse files Browse the repository at this point in the history
Remove latency measurements from TickerRateLimiter tests
  • Loading branch information
google-oss-prow[bot] authored Jun 10, 2024
2 parents 25b8cc4 + 37f8adf commit 4e21c98
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions pkg/cloud/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,17 @@ func TestTickerRateLimiter(t *testing.T) {
t.Parallel()

trl := NewTickerRateLimiter(100, time.Second)
start := time.Now()
for i := 0; i < 50; i++ {
err := trl.Accept(context.Background(), nil)
if err != nil {
t.Errorf("TickerRateLimiter.Accept = %v, want nil", err)
}
}
elapsed := time.Since(start)
if elapsed > time.Second {
t.Errorf("TickerRateLimiter.Accept took too long: %v, want <1s", elapsed)
}
if elapsed < 500*time.Millisecond {
t.Errorf("TickerRateLimiter.Accept took too short: %v, want >500ms", elapsed)
err := trl.Accept(context.Background(), nil)
if err != nil {
t.Errorf("TickerRateLimiter.Accept = %v, want nil", err)
}

// Use context that has been cancelled and expect a context error returned.
ctxCancelled, cancelled := context.WithCancel(context.Background())
cancelled()
// Verify context is cancelled by now.
<-ctxCancelled.Done()
err := trl.Accept(ctxCancelled, nil)
err = trl.Accept(ctxCancelled, nil)
if err != ctxCancelled.Err() {
t.Errorf("TickerRateLimiter.Accept() = %v, want %v", err, ctxCancelled.Err())
}
Expand Down

0 comments on commit 4e21c98

Please sign in to comment.