larry-robotics / elkodon

Elkodon - true zero-copy inter-process-communication in rust
Apache License 2.0
14 stars 2 forks source link

No `assert`s in threads of tests #25

Closed elfenpiff closed 8 months ago

elfenpiff commented 8 months ago

Required information

If a thread in a test encounters an assert and suddenly terminates, it is possible that some succeeding variables, required for terminating the whole tests, are not being set. Therefore, either avoid asserts in tests or use it only if it occurs not before such a test flow control variable.

elfenpiff commented 8 months ago

cc @elBoberido

elfenpiff commented 8 months ago

Reopened since also asserts outside of tests can cause deadlocks when control flow variables are set afterwards.

elBoberido commented 8 months ago

@elfenpiff I found this https://stackoverflow.com/questions/35988775/how-can-i-cause-a-panic-on-a-thread-to-immediately-end-the-main-thread/36031130#36031130

The following code would terminate the whole test when an assert in a thread fails. It can also be placed in a function which could be called at the start of a test

let orig_hook = panic::take_hook();
panic::set_hook(Box::new(move |panic_info| {
    // invoke the default handler and exit the process
    orig_hook(panic_info);
    process::exit(1);
}));