diff options
Diffstat (limited to 'src/time.rs')
| -rw-r--r-- | src/time.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/time.rs b/src/time.rs index 5e82f0c..9917f54 100644 --- a/src/time.rs +++ b/src/time.rs @@ -37,6 +37,14 @@ thread_local! { static CLOCK: std::cell::RefCell<Option<String>> = const { std::cell::RefCell::new(None) }; } +/// Freeze the clock for this thread, returning the previous pin if any. +/// +/// Test-tier only, together with `unpin` — the two are one capability and +/// gating half of it would leave a release binary able to freeze time and +/// unable to release it. The census never reported `pin` as test-only because +/// its name match also fires inside `upstream_pins` and `source_digests`; the +/// only callers in the crate are tests. +#[cfg(feature = "test-support")] pub fn pin(ts: &str) -> Option<String> { CLOCK.with(|c| { let mut slot = c.borrow_mut(); @@ -44,6 +52,8 @@ pub fn pin(ts: &str) -> Option<String> { }) } +/// Release a pin set by `pin`. See the note there about why both are gated. +#[cfg(feature = "test-support")] pub fn unpin() { CLOCK.with(|c| *c.borrow_mut() = None); } @@ -212,6 +222,7 @@ mod tests { // clock itself and need nothing else; the third test in that file pins a // lease against a pinned clock, which needs a database, so it stayed. + #[cfg(feature = "test-support")] #[test] fn a_pinned_clock_moves_relative_arithmetic_with_it() { pin("2026-01-01T00:00:00Z"); |
