diff options
Diffstat (limited to 'crates/shirabe/tests/common')
| -rw-r--r-- | crates/shirabe/tests/common/async_runtime.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/shirabe/tests/common/async_runtime.rs b/crates/shirabe/tests/common/async_runtime.rs new file mode 100644 index 00000000..e047315a --- /dev/null +++ b/crates/shirabe/tests/common/async_runtime.rs @@ -0,0 +1,23 @@ +//! Shared tokio runtime bridge for integration tests. +//! +//! `cargo test` runs `#[test]` fns concurrently on separate OS threads, so a per-call +//! `current_thread` Runtime would need one instance per caller. Instead this holds a single +//! process-wide `multi_thread` Runtime that tolerates concurrent `block_on()` callers, and every +//! test bridges into async code through it. +//! +//! Included into each integration-test binary via +//! `#[path = "../common/async_runtime.rs"] mod async_runtime;`. +#![allow(dead_code)] + +use std::sync::LazyLock; + +static RUNTIME: LazyLock<tokio::runtime::Runtime> = LazyLock::new(|| { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() +}); + +pub fn run<F: std::future::Future>(future: F) -> F::Output { + RUNTIME.block_on(future) +} |
