Static zebra_test::SINGLE_THREADED_RUNTIME

source ·
pub static SINGLE_THREADED_RUNTIME: Lazy<Runtime>
Expand description

A single-threaded Tokio runtime that can be shared between tests. This runtime should be used for tests that need a single thread for consistent timings.

This shared runtime should be used in tests that use shared background tasks. An example is with shared global Lazy<BatchVerifier> types, because they spawn a background task when they are first initialized. This background task is stopped when the runtime is shut down, so having a runtime per test means that only the first test actually manages to successfully use the background task. Using the shared runtime allows the background task to keep running for the other tests that also use it.

A shared runtime should not be used in tests that need to pause and resume the Tokio timer. This is because multiple tests might be sharing the runtime at the same time, so there could be conflicts with pausing and resuming the timer at incorrect points. Even if only one test runs at a time, there’s a risk of a test finishing while the timer is paused (due to a test failure, for example) and that means that the next test will already start with an incorrect timer state.