Skip to content

Commit deb55d9

Browse files
committed
docs(runtime): document the ManualClock set skew and as_override sharing
1 parent 7df51b1 commit deb55d9

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • crates/nexum-runtime/src/test_utils

crates/nexum-runtime/src/test_utils/clock.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ impl ManualClock {
4444
}
4545
}
4646

47-
/// Pin wall time to `time`. Times before the Unix epoch clamp to it.
47+
/// Pin wall time to `time`, leaving the monotonic reading untouched.
48+
/// Times before the Unix epoch clamp to it. Because it does not move
49+
/// monotonic, a `set` after an `advance` can put wall time behind the
50+
/// monotonic source; the two only stay in step under `advance`.
4851
pub fn set(&self, time: SystemTime) {
4952
let wall = time.duration_since(UNIX_EPOCH).unwrap_or(Duration::ZERO);
5053
self.locked().wall = wall;
@@ -59,7 +62,11 @@ impl ManualClock {
5962
}
6063

6164
/// Build a [`WasiClockOverride`] backed by this clock for both the wall and
62-
/// monotonic sources.
65+
/// monotonic sources. The two `Arc`s wrap separate `clone`s of the same
66+
/// `ManualClock`, which share one inner `Arc<Mutex<_>>`, so both handles
67+
/// read and drive the same time. Swapping a `clone` for a fresh
68+
/// `ManualClock::new()` would split that state and silently break the
69+
/// override.
6370
pub fn as_override(&self) -> WasiClockOverride {
6471
WasiClockOverride::new(Arc::new(self.clone()), Arc::new(self.clone()))
6572
}

0 commit comments

Comments
 (0)