MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / check_determinism

Function check_determinism

crates/runtime/src/sim_std.rs:33–62  ·  view source on GitHub ↗

Run the same future factory twice and assert that both runs consume the same deterministic RNG/scheduler trace. Each pass runs on a fresh OS thread so thread-local std state is not shared between the recording and replay passes.

(seed: u64, make_future: M)

Source from the content-addressed store, hash-verified

31/// Each pass runs on a fresh OS thread so thread-local std state is not shared
32/// between the recording and replay passes.
33pub fn check_determinism<M, F>(seed: u64, make_future: M) -> F::Output
34where
35 M: Fn() -> F + Clone + Send + 'static,
36 F: Future + 'static,
37 F::Output: Send + 'static,
38{
39 let first = make_future.clone();
40 let log = std::thread::spawn(move || {
41 let mut runtime = sim::Runtime::new(seed);
42 runtime.enable_determinism_log();
43 block_on(&mut runtime, first());
44 runtime
45 .take_determinism_log()
46 .expect("determinism log should be enabled")
47 })
48 .join()
49 .map_err(|payload| panic_with_seed(seed, payload))
50 .unwrap();
51
52 std::thread::spawn(move || {
53 let mut runtime = sim::Runtime::new(seed);
54 runtime.enable_determinism_check(log);
55 let output = block_on(&mut runtime, make_future());
56 runtime.finish_determinism_check().unwrap_or_else(|err| panic!("{err}"));
57 output
58 })
59 .join()
60 .map_err(|payload| panic_with_seed(seed, payload))
61 .unwrap()
62}
63
64fn panic_with_seed(seed: u64, payload: Box<dyn core::any::Any + Send>) -> ! {
65 eprintln!("note: run with --seed {seed} to reproduce this error");

Calls 11

block_onFunction · 0.85
firstFunction · 0.85
panic_with_seedFunction · 0.85
joinMethod · 0.80
newFunction · 0.50
cloneMethod · 0.45
unwrapMethod · 0.45
take_determinism_logMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…