diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-17 18:22:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-17 18:22:54 +0900 |
| commit | 6aa4808a0936e85384100f13e07aa7bea559bc3c (patch) | |
| tree | fe2c3008fce0825a8d74c37588ce8bece91e3df3 /crates/shirabe/tests/common/async_runtime.rs | |
| parent | e44085eb742cb14dff22de054ef19fe725a4e2c2 (diff) | |
| download | php-shirabe-6aa4808a0936e85384100f13e07aa7bea559bc3c.tar.gz php-shirabe-6aa4808a0936e85384100f13e07aa7bea559bc3c.tar.zst php-shirabe-6aa4808a0936e85384100f13e07aa7bea559bc3c.zip | |
refactor(tests-async): unify duplicated tokio runtime bridges
11 downloader/installer integration-test files each redefined an
identical current_thread `run()` helper to block on async code. Extract
one shared multi_thread Runtime into tests/common/async_runtime.rs so
concurrent #[test] threads can all block_on it, matching the direction
item 7 (top-level Runtime) will take in production code.
Diffstat (limited to 'crates/shirabe/tests/common/async_runtime.rs')
| -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) +} |
