-
Notifications
You must be signed in to change notification settings - Fork 50
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
Validate tick_duration
millisecond resolution
#178
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving this!
src/builder.rs
Outdated
@@ -193,6 +193,11 @@ impl Builder { | |||
panic!("Maximum message latency must be greater than minimum."); | |||
} | |||
|
|||
if self.config.tick.as_nanos() % Duration::from_millis(1).as_nanos() != 0 { | |||
// Tick duration is used for tokio::time::sleep, which requires millisecond resolution. | |||
panic!("Tick duration resolution is in milliseconds, but value provided would require higher.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding the provided value in the panic message to aid in debugging.
@@ -193,6 +193,11 @@ impl Builder { | |||
panic!("Maximum message latency must be greater than minimum."); | |||
} | |||
|
|||
if self.config.tick.as_nanos() % Duration::from_millis(1).as_nanos() != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be simpler to just check < Duration::from_millis(1)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think someone could provide a value that was > 1 ms, but had a higher resolution, e.g. Duration::from_micros(1500)
, which I believe we would want to disallow still given that comment on tokio::time::sleep
.
Though, we might want to disallow Duration::ZERO
in addition I suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs to be this restrictive. Given that the runtime is paused we aren't actually running for the duration, we are simply advancing time by it.
Duration::ZERO
is a good callout, and I'm not actually sure what would happen in that case. My guess is that nothing runs.
Hi! I noticed some strange behavior while running a simulation where the tick duration was sub-millisecond, and discovered that
tokio::time::sleep
apparently uses millisecond resolution.I added some validation to the builder, to panic whenever a duration with higher than ms resolution is supplied, since it looked like some other validation was already happening here. Let me know if this seems useful.
Love the project btw!