Hey,
I want to test that a server on a separate thread received a message correctly.
Therefore I tried to put an assert!() into the closure I hand to the server:
thread::spawn(move||{
let mut server = NotificationServer::new();
server.start( |notification|{
assert!(notification.actions[0] == "action1");
})
});
The assertion causes the thread to panic, but the test does not count as failed.
running 1 test
thread '<unnamed>' panicked at 'index out of bounds: the len is 4 but the index is 4', ../src/libcollections/vec.rs:1041
test actions_vec ... ok
What do I have to do to make the test recognize the panicked thread?
Thank you, that did it. I hadn't used thread extensively before.
Do you know of a way to force tests to run single threaded without adding -j1 to cargo test, perhaps by adding something to Cargo.toml. My tests start a server each and therefore must not be run in parallel
Not off the top of my head. I seem to remember someone asking something about it here or on Reddit, but I didn't stay around for the answer. They had problems with initializing some global value, or something like that...