use rusty_bubbles::cursor;
use std::sync::{Arc, Mutex};
#[test]
fn blink_cmd_data_race() {
let mut m = cursor::new();
let speed = m.blink_speed;
let cmd = m.blink().expect("blink should return a command");
let m = Arc::new(Mutex::new(m));
let t1 = std::thread::spawn(move || {
std::thread::sleep(speed * 3);
cmd();
});
let t2 = {
let m = m.clone();
std::thread::spawn(move || {
std::thread::sleep(speed * 2);
let mut m = m.lock().unwrap();
m.blink();
})
};
t1.join().expect("blink command thread");
t2.join().expect("re-blink thread");
let mut m = m.lock().unwrap();
assert!(m.blink().is_some(), "blink should return a command");
}