-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom timer instead of time.Now() cloak time #69
Comments
Can you try // NanoTime returns the current time in nanoseconds from a monotonic clock.
//go:linkname NanoTime runtime.nanotime
func NanoTime() int64 |
This is one possible way to change wall time. I suppose you have an interface with one method:
Integer type
It allows you to use whatever representation of time you want:
The point of this change is that everyone may need to represent time in a different way. I would let the current behavior with wall time, but add new constructor that accepts timer interface. |
@pheepi |
I have my app using the cache library and several tests that check if records do not expire in a given timeout. These tests fail occasionally, because they run on a server sharing CPU with other services. I can never fix them, because the library depends on cloak time from
time.Now()
. The only ultimate solution here is to mock time. Do you think it would be possible to replacetime.Now()
with an interface representing current time? It would provide function Now(), but it could be custom and parameterized. Default implementation would still usetime.Now().Unix()
, but custom timer could be passed as a parameter. I have already written my own change.By the way, it may also partly resolve issue #51.
The text was updated successfully, but these errors were encountered: