x/time/rate: allow injecting of time functions to make testing easier #21210
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
What did you do?
Limiter from x/time/rate directly uses time functions without ability to provide replacement.
When testing code that uses Limiter, it is hard to write a test that doesn't involve the passing of actual wall clock time.
It would be convenient if we could inject a function to provide the time functions used by Limiter's methods, like time.Now()
There are also examples of clocks that would be convenient to inject, such as andres-erbsen/clock. Though just a replacement for time.Now() is likely sufficient.
What did you expect to see?
What did you see instead?
lim := rate.NewLimiter(1.0, 1)
System details
The text was updated successfully, but these errors were encountered: