-
Notifications
You must be signed in to change notification settings - Fork 18k
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
runtime: expose faketime for testing on normal architectures #22549
Comments
This isn't an interface we want to guarantee & support long-term in its current form. |
please? |
There are a number of fake clock implementations in third_party packages. If you want one in the standard library, you need to tell us what it does that can not be done in a different package. |
When I wrote the thing that @whyrusleeping linked above, I tried various fake clock implementations. There are multiple issues with them:
|
How would exposing the runtime's fake clock solve any of those problems? What would the API be? |
I understand that Maybe it's best to talk about what we want to achieve, rather than talking about how to expose the existing fake clock as is. What I wanted at the time was a way to run my program where:
We used I think it would nice to have 'official' support for fake time because code under test could just use the normal clock and timers as provided by package time, but run with virtual time for testing/simulation purposes. Making this a NaCl-only feature is reasonable because it's an isolated environment without any access to the OS. |
The key here is that we don't skip forward in time to unblock sleepers until all goroutines are blocked (sleeping, or waiting on channels). The only way to do this outside of exposing this runtime.faketime code would be to wrap all of our code in extra logic to inform our custom scheduler when we're blocking (meaning replacing all channel send/recvs with My primary usecase here is testing code that relies on timing between different actors. Currently, these tests take a very long time because i'm trying to use 'close to real' values for the timeouts and delays. When using these 'close to real' values, the code runs and works as expected. But if I ratchet down those durations, then fluctuations in the scheduler and actual runtime costs make the simulation less accurate. One way to satisfy my needs would be to add a callback that I can set for when all goroutines are blocked (instead of the current behavior where it panics). Then i could implement my scheduler such that all sleep calls just block on a channel, and when that callback hits, i roll forward time until i hit the first deadline set by one of those sleeps, and unblock that sleep. |
something like: runtime.SetDeadlockHandler(func() {
myscheduler.AdvanceTime()
}) And then in runtime/proc.go, near the end of |
Should this be closed as a duplicate of #67434, which is under active development as of Go 1.24? |
The faketime 'secret feature' that gets used by the playground is actually really interesting to use for writing tests that normally depend on time. For example, go-ethereum uses it to run network testing simulations reproducibly
The downside, is that its hacky to enable, and it only works on nacl. Is there any way we can get this exposed on other architectures?
cc @fjl and @karalabe
The text was updated successfully, but these errors were encountered: