pub(crate) fn paused() -> ::tokio::runtime::Runtime {
::tokio::runtime::Builder::new_current_thread()
.enable_all()
.start_paused(true)
.build()
.expect("build the paused test runtime")
}
pub(crate) fn single_thread_pool_runtime() -> ::tokio::runtime::Runtime {
::tokio::runtime::Builder::new_current_thread()
.enable_all()
.max_blocking_threads(1)
.build()
.expect("build a runtime with a one-thread blocking pool")
}
pub(crate) fn assert_current_thread() {
assert_eq!(
::tokio::runtime::Handle::current().runtime_flavor(),
::tokio::runtime::RuntimeFlavor::CurrentThread,
"this test's seam is thread-local: its futures must be polled on this thread"
);
}
struct Woken(std::sync::Mutex<std::sync::mpsc::Sender<()>>);
impl std::task::Wake for Woken {
fn wake(self: std::sync::Arc<Self>) {
_ = self.0.lock().expect("the sender").send(());
}
}
pub(crate) fn counting_waker() -> (std::task::Waker, std::sync::mpsc::Receiver<()>) {
let (woken, wakes) = std::sync::mpsc::channel();
let waker = std::task::Waker::from(std::sync::Arc::new(Woken(std::sync::Mutex::new(woken))));
(waker, wakes)
}
#[cfg(test)]
#[path = "test_runtime_tests.rs"]
mod test_runtime_tests;