mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
The test-util feature flag is only intended to be used with tests. However, it is possible to enable it in release mode accidentally. This patch reduces the overhead of `Instant::now()` when the `test-util` feature flag is enabled but `time::pause()` is not called. The optimization is implemented by adding a static atomic flag that tracks if `time::pause()` has ever been called. In `Instant::now()`, the atomic flag is first checked before the thread-local and mutex are accessed.
15 lines
362 B
Rust
15 lines
362 B
Rust
#![cfg(all(feature = "full"))]
|
|
|
|
use tokio::time::{Duration, Instant};
|
|
|
|
#[tokio::test(start_paused = true)]
|
|
async fn test_start_paused() {
|
|
let now = Instant::now();
|
|
|
|
// Pause a few times w/ std sleep and ensure `now` stays the same
|
|
for _ in 0..5 {
|
|
std::thread::sleep(Duration::from_millis(1));
|
|
assert_eq!(now, Instant::now());
|
|
}
|
|
}
|