Skip to content

Commit

Permalink
Merge pull request #210 from AwesomePatrol/fix-ticker-rate-limiter-test
Browse files Browse the repository at this point in the history
Split TickerRateLimiter test
  • Loading branch information
google-oss-prow[bot] authored Jun 20, 2024
2 parents 0c93851 + b056f7e commit 0f8079e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/cloud/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,26 @@ func TestMinimumRateLimiter(t *testing.T) {
}
}

func TestTickerRateLimiter(t *testing.T) {
func TestTickerRateLimiter_Tick(t *testing.T) {
t.Parallel()

trl := NewTickerRateLimiter(100, time.Second)
err := trl.Accept(context.Background(), nil)
if err != nil {
t.Errorf("TickerRateLimiter.Accept = %v, want nil", err)
}
}

func TestTickerRateLimiter_Cancel(t *testing.T) {
t.Parallel()

trl := NewTickerRateLimiter(1, time.Hour)
// 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 0f8079e

Please sign in to comment.