From e7922f3dd1d985dcb993b624146b2492183f3a11 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 17:04:57 +0000 Subject: time: relative arithmetic honors the pinned clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `now()` returned the pinned instant when a test had pinned one, but `secs_ago`/`secs_ahead` called `Utc::now()` directly (m-1). Anything built from them — every lease expiry, every `next_check_at`, every cooldown cutoff — was therefore computed against the real wall clock and then compared against the pinned one. A test that pinned 2026-01-01 and took a 90-second lease got an expiry 90 seconds after *today*, so the reaper comparing `lease_expires_at < now()` saw a lease that would not expire for a century, or one that had expired millions of seconds ago, depending on which way the pin pointed. The test still passed, because nothing asserted on the number. Both now go through a `base()` that reads the pinned instant, so a pinned test computes and compares on the same clock. `tests/time.rs` pins the arithmetic directly and then does the thing the bug actually broke: claim a lease under a pinned clock, assert the expiry is 90 seconds after the pinned now, assert the reaper sees nothing yet, advance the pinned clock 91 seconds, and assert it reaps. --- tests/common/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/common/mod.rs') diff --git a/tests/common/mod.rs b/tests/common/mod.rs index de5f87e..58c6dae 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -155,6 +155,26 @@ impl Env { }) .unwrap() } + + /// The same for a text column, so a test can read a timestamp back. + pub fn query_str(&self, sql: &str, params: &[P]) -> Option { + let sql = sql.to_string(); + let params: Vec

= params.to_vec(); + self.db + .read(move |c| { + let refs: Vec<&dyn rusqlite::ToSql> = params + .iter() + .map(|p| match p { + P::I(i) => i as &dyn rusqlite::ToSql, + P::S(s) => s as &dyn rusqlite::ToSql, + }) + .collect(); + use rusqlite::OptionalExtension; + Ok(c.query_row(&sql, rusqlite::params_from_iter(refs.iter()), |r| r.get::<_, String>(0)) + .optional()?) + }) + .unwrap() + } } /// A test parameter. Owned so it can cross the writer-actor channel. -- cgit v1.2.3