madsim-rs / madsim

Magical Deterministic Simulator for distributed systems in Rust.
Apache License 2.0
618 stars 41 forks source link

How to retrieve madsim seed when the test case was canceled by cargo-nextest due to timeout #217

Open Phoenix500526 opened 3 weeks ago

Phoenix500526 commented 3 weeks ago

When running madsim tests with cargo-nextest, it is possible that madsim tests may be canceled by cargo-nextest due to timeouts. In such cases, the seed generated by madsim cannot be retrieved. How should this issue be resolved? Would adding an function hook on kill, like issue #6 , solve the problem?

wangrunji0408 commented 3 weeks ago

I think the function hook mentioned in #6 is not exactly what you want. #6 discussed how to do clean up when the simulated node is restarted. But now we are talking about the moment when the entire simulation is killed.

A simple solution I can think of is to print the seed at the beginning of each test.

eprintln!("seed = {}", madsim::runtime::Handle::current().seed());

This way, if the test is cancelled due to a timeout, you can retrieve the seed from stdout or stderr.