-
Notifications
You must be signed in to change notification settings - Fork 7
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
compatibility with SystemTime #3
Comments
We can just add a If you provide the impl (it'd be mostly copy-paste of the original code, but with the minor changes you need) I'll surely accept the PR. If you need any help with the impls, I can also help with that. |
Yah, I'm probably trying to over think it.
…On Wed, Apr 19, 2023, 7:21 p.m. museun ***@***.***> wrote:
We can just add a SystemTime api that mostly duplicates MockClock,
MockSystemTime::advance et al
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAH2SO5C5LUWRY6PPEEQBTXCB6SHANCNFSM6AAAAAAXEAGQZU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
After looking at the SystemTime api, I think I can provide a unified api. but I'm not 100% certain. (Its been a few years since I've actually looked at the code in this crate -- its simple and it works, so I didn't have a need to poke at it) |
So, one problem I can see immediately is that because there's a "global" time source, For testing, I think the shared determinism will actually be the correct choice. So, its only a problem in "correctness" in a real system |
And a final problem: https://doc.rust-lang.org/std/time/struct.SystemTimeError.html this is a new type wrapping a duration, but I can't create a value for the type. So, either the error types will be different or I have to change the signature. the wasi impl in std returns a |
Considering testers have full control over how time advances, I don't think
it'll be too surprising. We can already use your set_time api to make
time go backwards...
…On Wed, Apr 19, 2023, 7:50 p.m. museun ***@***.***> wrote:
So, one problem I can see immediately is that because there's a "global"
time source, mock_instant::SystemTime and mock_instant::Instant will
share the time 'start' time. This isn't a problem in practice, but it could
be a be surprising if one is expecting the monotonic vs non-monotonic
distinction between the two types in std.
For testing, I think the shared determinism will actually be the correct
choice. So, its only a problem in "correctness" in a real system
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAH2SJ6YEV5VVQX76N7IWTXCCB5NANCNFSM6AAAAAAXEAGQZU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Yah, in my snippet I added a new SystemTimeError to your crate, and then
used the test cfg to selectively choose whether to import SystemTimeError
from the crate or from std.
…On Wed, Apr 19, 2023, 8:08 p.m. museun ***@***.***> wrote:
And a final problem:
https://doc.rust-lang.org/std/time/struct.SystemTimeError.html this is a
new type wrapping a duration, but I can't create a value for the type. So,
either the error types will be different or I have to change the signature.
the wasi impl in std returns a Result<Duration, Duration> but thats
because wasi doesn't required std::error::Error (or more specifically the
backtrace part of it).
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAH2SONW6CTTANJV4HRLA3XCCEARANCNFSM6AAAAAAXEAGQZU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Well, my concern is that if you do
Then both |
I simply added the SystemTime/SystemTimeError wrapper and added a 2nd internal state, and the following functions on MockClock:
I think this is sufficient, if that looks usable I can merge it and publish the 0.3 version with it. |
I've published this as 0.3.0: https://docs.rs/mock_instant/0.3.0/mock_instant/ |
This crate looks super useful to me. However, I need to mock SystemTime, not Instant. SystemTime has almost-but-not-quite the same API as Instant. I can almost-but-not-quite
use mock_instant::Instant as SystemTime
.I can fork your crate, but it'd be nice if there was some way of unifying the two. Here's what I need to use this crate to mock SystemTime, for my use case. It's not complete, of course.
Some of the changes would be non-disruptive if I PR'd them, but I'm not sure how to deal with the change in return signature for functions like
duration_since
.The text was updated successfully, but these errors were encountered: