mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
runtime: panic when event_interval is set to 0 (#7838)
This commit is contained in:
@@ -1123,6 +1123,10 @@ impl Builder {
|
|||||||
/// will minimize that overhead while still keeping the scheduler responsive to
|
/// will minimize that overhead while still keeping the scheduler responsive to
|
||||||
/// events.
|
/// events.
|
||||||
///
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This function will panic if 0 is passed as an argument.
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
@@ -1136,7 +1140,9 @@ impl Builder {
|
|||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[track_caller]
|
||||||
pub fn event_interval(&mut self, val: u32) -> &mut Self {
|
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.event_interval = val;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,18 @@ fn builder_global_queue_interval_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
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 {
|
fn current_thread() -> Runtime {
|
||||||
tokio::runtime::Builder::new_current_thread()
|
tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
|||||||
Reference in New Issue
Block a user