My application is made of 2 executables. For the testing scenario I just spawn 2 (or more) threads that run main functions of those executables. I want to test that a certain condition occurs, when it does I'd like to just terminate the test case as it passes already.
How can I do that, given that terminating the threads corrupts the process?
Roughly the structure is like:
std:thread::scope{|scope| {
scope.spawn(main1)
scope.spawn(main2)
// await the condition
}
I don't want to modify the two mains, because this modification only makes sense for the testing and is completely pointless for the actual implementation
I can know in the above code when the condition appears, so this is not a problem
You'll have to modify the mains if you want the threads to exit early. You can use a type parameter to make sure it doesn't affect the performance of the non-test build though.
As long as the trait impl for release builds uses boolean constants the compiler shouldn't have a problem removing the conditionals entirely. It actually looks like even the test version that uses struct fields rather than direct constants still optimizes out the conditionals if you build with full optimizations
You can run the actual executables from an integration test; Cargo will tell you the path to them via the CARGO_BIN_EXE_<targetname> environment variable, just for this purpose.