aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/common/async_runtime.rs
blob: e047315a6a93b6932140a20514458be79eb1f062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)
}