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)
| 31 | /// Each pass runs on a fresh OS thread so thread-local std state is not shared |
| 32 | /// between the recording and replay passes. |
| 33 | pub fn check_determinism<M, F>(seed: u64, make_future: M) -> F::Output |
| 34 | where |
| 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 | |
| 64 | fn panic_with_seed(seed: u64, payload: Box<dyn core::any::Any + Send>) -> ! { |
| 65 | eprintln!("note: run with --seed {seed} to reproduce this error"); |
searching dependent graphs…