| package util |
|
|
| import ( |
| "testing" |
| "time" |
| ) |
|
|
| |
| func BenchmarkCalculateBackoffDuration_AuthError(b *testing.B) { |
| statusCode := 401 |
| now := time.Now() |
|
|
| b.ReportAllocs() |
| for b.Loop() { |
| _ = CalculateBackoffDuration(0, time.Time{}, now, &statusCode) |
| } |
| } |
|
|
| |
| func BenchmarkCalculateBackoffDuration_OtherError(b *testing.B) { |
| statusCode := 500 |
| now := time.Now() |
|
|
| b.ReportAllocs() |
| for b.Loop() { |
| _ = CalculateBackoffDuration(0, time.Time{}, now, &statusCode) |
| } |
| } |
|
|
| |
| func BenchmarkCalculateBackoffDuration_ExponentialBackoff(b *testing.B) { |
| statusCode := 401 |
| now := time.Now() |
| prevMs := int64(5 * time.Minute / time.Millisecond) |
|
|
| b.ReportAllocs() |
| for b.Loop() { |
| _ = CalculateBackoffDuration(prevMs, time.Unix(0, 0), now, &statusCode) |
| } |
| } |
|
|
| |
| func BenchmarkCalculateBackoffDuration_NilStatusCode(b *testing.B) { |
| now := time.Now() |
|
|
| b.ResetTimer() |
| b.ReportAllocs() |
| for i := 0; i < b.N; i++ { |
| _ = CalculateBackoffDuration(0, time.Time{}, now, nil) |
| } |
| } |
|
|
| |
| func BenchmarkCalculateBackoffDuration_MaxLimit(b *testing.B) { |
| statusCode := 401 |
| now := time.Now() |
| prevMs := int64(20 * time.Minute / time.Millisecond) |
|
|
| b.ReportAllocs() |
| for b.Loop() { |
| _ = CalculateBackoffDuration(prevMs, time.Unix(0, 0), now, &statusCode) |
| } |
| } |
|
|
| |
| func BenchmarkCalculateCooldownDuration(b *testing.B) { |
| now := time.Now() |
| until := now.Add(5 * time.Minute) |
|
|
| b.ReportAllocs() |
| for b.Loop() { |
| _ = CalculateCooldownDuration(until, now) |
| } |
| } |
|
|