Last active
June 4, 2020 10:56
-
-
Save yammmt/d57ce7566c9d51a30231fc2f83c5f4d3 to your computer and use it in GitHub Desktop.
Failed to test panic with Rayon crate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Author
yammmt
commented
Jun 4, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment