jiff/tests/init/mod.rs
Andrew Gallant f92871a2c7
Some checks failed
ci / test-core (nightly, ubuntu-latest, nightly) (push) Has been cancelled
ci / test-default (beta, ubuntu-latest, beta) (push) Has been cancelled
ci / test-default (macos, macos-latest, stable) (push) Has been cancelled
ci / test-default (nightly, ubuntu-latest, nightly) (push) Has been cancelled
ci / test-default (stable, ubuntu-latest, stable) (push) Has been cancelled
ci / test-all (macos, macos-latest, nightly) (push) Has been cancelled
ci / test-all (nightly, ubuntu-latest, nightly) (push) Has been cancelled
ci / test-only-bundle (macos, macos-latest, nightly) (push) Has been cancelled
ci / test-only-bundle (nightly, ubuntu-latest, nightly) (push) Has been cancelled
ci / test-core (macos, macos-latest, nightly) (push) Has been cancelled
ci / test-various-feature-combos (macos, macos-latest, nightly) (push) Has been cancelled
ci / test-various-feature-combos (nightly, ubuntu-latest, nightly) (push) Has been cancelled
ci / test-release (push) Has been cancelled
ci / test-doc (push) Has been cancelled
ci / test-bench (push) Has been cancelled
ci / test-miri (push) Has been cancelled
ci / win-msvc (push) Has been cancelled
ci / win-gnu (push) Has been cancelled
ci / msrv (push) Has been cancelled
ci / integrations (push) Has been cancelled
ci / examples (push) Has been cancelled
ci / time-zone-init (macos-latest) (push) Has been cancelled
ci / time-zone-init (ubuntu-24.04-arm) (push) Has been cancelled
ci / time-zone-init (ubuntu-latest) (push) Has been cancelled
ci / time-zone-init (windows-latest) (push) Has been cancelled
ci / cross (aarch64-linux-android) (push) Has been cancelled
ci / cross (aarch64-unknown-linux-gnu) (push) Has been cancelled
ci / cross (i686-unknown-linux-gnu) (push) Has been cancelled
ci / cross (s390x-unknown-linux-gnu) (push) Has been cancelled
ci / cross (x86_64-linux-android) (push) Has been cancelled
ci / cross (powerpc-unknown-linux-gnu) (push) Has been cancelled
ci / cross (powerpc64-unknown-linux-gnu) (push) Has been cancelled
ci / riscv32imc-unknown-none-elf (push) Has been cancelled
ci / wasm32-wasip1 (push) Has been cancelled
ci / wasm32-unknown-emscripten (push) Has been cancelled
ci / wasm32-unknown-uknown (push) Has been cancelled
ci / docsrs (push) Has been cancelled
ci / rustfmt (push) Has been cancelled
ci / generated (push) Has been cancelled
tests: improve test failure message
This test is failing intermittently on macOS. Which means that the
initialization of the zoneinfo database is taking more than 500ms. I had
scrutinized the CI logs and timestamps, and it looks like it's just
random I/O delay when traversing the zoneinfo directory. Sigh.
2025-10-23 13:27:12 -04:00

55 lines
2.2 KiB
Rust

/// This test is meant to be run on its own as the only thing in a CI job.
///
/// It's supposed to test how long it takes for the first call to
/// `Zoned::now()` to run. The specific problem is that, when this test was
/// written, Jiff would walk `/usr/share/zoneinfo` and catalog all time zones
/// in that directory. While this is generally not much of a problem, it can be
/// on a very slow file system. In particular, this can evolve a few syscalls
/// per file, and there might be a couple thousand files inside the directory.
/// Moreover, Jiff was doing a 4-byte read of each file to check if it was TZif
/// or not.
///
/// Ref: https://github.com/BurntSushi/jiff/issues/366
#[cfg(feature = "std")]
#[test]
fn zoned_now() {
use std::time::{Duration, Instant};
use jiff::Zoned;
let _ = crate::Logger::init();
let start = Instant::now();
println!("{}", Zoned::now());
let first = Instant::now().duration_since(start);
println!("first-run-elapsed-microseconds:{}", first.as_micros());
let start = Instant::now();
println!("{}", Zoned::now());
let second = Instant::now().duration_since(start);
println!("second-run-elapsed-microseconds:{}", second.as_micros());
// These are somewhat arbitrary, but if `Zoned::now()` starts
// going above 100ms (even in slow CI), then it probably makes
// sense to investigate. At time of writing (2025-05-09), the
// biggest time observed here was ~33ms.
//
// OK, apparently CI is stupidly flaky. So I bumped this up to
// 500ms. Sigh. 500ms is definitely not great.
let limit = Duration::from_millis(500);
assert!(
first < limit,
"first `Zoned::now()` call should complete in less than {limit:?}, \
but it took {first:?}",
);
// The second call should run soon enough that the cached
// directory traversal results are still valid. So this should
// be extremely fast. Ideally even less than 1µs, but we give
// CI wide latitude.
let limit = Duration::from_millis(500);
assert!(
second < limit,
"second `Zoned::now()` call should complete in less than {limit:?}, \
but it took {second:?}",
);
}