mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
Pausing time is a capability added to assist with testing Tokio code dependent on time. Currently, the capability implicitly requires the current_thread runtime. This change enforces the requirement by panicking if called from a multi-threaded runtime.
34 lines
649 B
Rust
34 lines
649 B
Rust
#![warn(rust_2018_idioms)]
|
|
#![cfg(feature = "full")]
|
|
|
|
use tokio_test::assert_err;
|
|
|
|
#[tokio::test]
|
|
async fn pause_time_in_main() {
|
|
tokio::time::pause();
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn pause_time_in_task() {
|
|
let t = tokio::spawn(async {
|
|
tokio::time::pause();
|
|
});
|
|
|
|
t.await.unwrap();
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
|
#[should_panic]
|
|
async fn pause_time_in_main_threads() {
|
|
tokio::time::pause();
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
|
async fn pause_time_in_spawn_threads() {
|
|
let t = tokio::spawn(async {
|
|
tokio::time::pause();
|
|
});
|
|
|
|
assert_err!(t.await);
|
|
}
|