Skip to content

Instantly share code, notes, and snippets.

@yammmt
Last active June 4, 2020 10:56
Show Gist options
  • Save yammmt/d57ce7566c9d51a30231fc2f83c5f4d3 to your computer and use it in GitHub Desktop.
Save yammmt/d57ce7566c9d51a30231fc2f83c5f4d3 to your computer and use it in GitHub Desktop.
Failed to test panic with Rayon crate
use std::sync::mpsc;
use std::thread;
#[derive(Debug)]
enum ThreadMessage {
Hello,
Close,
Panic,
}
fn another_thread(tx: mpsc::Sender<ThreadMessage>, rx: mpsc::Receiver<ThreadMessage>) {
loop {
match rx.recv().unwrap() {
ThreadMessage::Hello => {
println!("Hello from main");
tx.send(ThreadMessage::Hello).unwrap();
}
ThreadMessage::Close => {
tx.send(ThreadMessage::Close).unwrap();
break;
}
ThreadMessage::Panic => {
panic!("panic!");
}
}
}
}
#[test]
#[should_panic]
fn test_panic() {
let (tx1, _rx1) = mpsc::channel();
let (tx2, rx2) = mpsc::channel();
rayon::spawn(move || {
another_thread(tx1, rx2)
});
tx2.send(ThreadMessage::Panic).unwrap();
}
@yammmt
Copy link
Author

yammmt commented Jun 4, 2020

running 1 test
test test_panic ... FAILED
thread '<unnamed>
failures:
' panicked at 'panic!', src/main.rs
:---- test_panic stdout ----
note: test did not panic as expected
24
failures:
:17    test_panic


test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment