runtime: panic when event_interval is set to 0 (#7838)

This commit is contained in:
Mattia Pitossi
2026-01-06 09:31:56 +00:00
committed by GitHub
parent 09ad5367b8
commit df73fa2188
2 changed files with 18 additions and 0 deletions
+6
View File
@@ -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
}
+12
View File
@@ -82,6 +82,18 @@ fn builder_global_queue_interval_panic_caller() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn builder_event_interval_interval_panic_caller() -> Result<(), Box<dyn Error>> {
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()