From ed2ada813fccbe31333086661a78c97f60e57170 Mon Sep 17 00:00:00 2001 From: Stephen Balogh Date: Fri, 19 Jul 2024 16:06:54 -0700 Subject: [PATCH 1/2] fix: validate tick duration resolution --- src/builder.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index b92a34a..5dd1d11 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -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.") + } + let world = World::new( self.link.clone(), rng, @@ -218,4 +223,12 @@ mod tests { .max_message_latency(Duration::from_millis(50)) .build(); } + + #[test] + #[should_panic] + fn invalid_tick_duration() { + let _sum = Builder::new() + .tick_duration(Duration::from_micros(500)) + .build(); + } } From 3c222a62b18d7ae0574d7769087d4f210e8a50a2 Mon Sep 17 00:00:00 2001 From: Stephen Balogh Date: Sat, 20 Jul 2024 16:44:49 -0700 Subject: [PATCH 2/2] tweaks --- src/builder.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 5dd1d11..a6d568c 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -195,7 +195,11 @@ impl Builder { 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.") + panic!("Tick duration resolution is in milliseconds, but value provided would require higher: {:?}.", self.config.tick) + } + + if self.config.tick.is_zero() { + panic!("Tick duration of zero is not supported.") } let world = World::new(