diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs index e3f6f465c..b5f23e9c5 100644 --- a/tokio/src/runtime/builder.rs +++ b/tokio/src/runtime/builder.rs @@ -1123,6 +1123,10 @@ impl Builder { /// will minimize that overhead while still keeping the scheduler responsive to /// events. /// + /// # Panics + /// + /// This function will panic if 0 is passed as an argument. + /// /// # Examples /// /// ``` @@ -1136,7 +1140,9 @@ impl Builder { /// # } /// # } /// ``` + #[track_caller] pub fn event_interval(&mut self, val: u32) -> &mut Self { + assert!(val > 0, "event_interval must be greater than 0"); self.event_interval = val; self } diff --git a/tokio/tests/rt_panic.rs b/tokio/tests/rt_panic.rs index 5c0bd37a7..21c1fd200 100644 --- a/tokio/tests/rt_panic.rs +++ b/tokio/tests/rt_panic.rs @@ -82,6 +82,18 @@ fn builder_global_queue_interval_panic_caller() -> Result<(), Box> { Ok(()) } +#[test] +fn builder_event_interval_interval_panic_caller() -> Result<(), Box> { + let panic_location_file = test_panic(|| { + let _ = Builder::new_multi_thread().event_interval(0).build(); + }); + + // The panic location should be in this file + assert_eq!(&panic_location_file.unwrap(), file!()); + + Ok(()) +} + fn current_thread() -> Runtime { tokio::runtime::Builder::new_current_thread() .enable_all()