From 6aa4808a0936e85384100f13e07aa7bea559bc3c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 17 Jul 2026 18:22:54 +0900 Subject: 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. --- crates/shirabe/tests/common/async_runtime.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 crates/shirabe/tests/common/async_runtime.rs (limited to 'crates/shirabe/tests/common/async_runtime.rs') 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 = LazyLock::new(|| { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() +}); + +pub fn run(future: F) -> F::Output { + RUNTIME.block_on(future) +} -- cgit v1.3.1