Timeout not working as expected #490
-
So I have an iterator that calculates prime numbers. I tried running cargo-mutants and saw that some mutations cause timeouts. So I wrote a test that is supposed to catch infinite loops: #[test]
fn primes_generates_1000_in_less_than_2s() {
let (tx, rx) = std::sync::mpsc::channel();
let _ = std::thread::spawn(move || {
let _: Vec<_> = Primes::with_capacity(1000).take(1000).collect();
let _ = tx.send(());
});
assert!(rx.recv_timeout(std::time::Duration::from_secs(2)).is_ok());
} I ran cargo-mutants again, but it still reports timeouts for these mutations. Am I misunderstanding something about how cargo-mutants works? Is my test not actually able to catch timeouts for some reason? EDIT: So it looks like there's something about the way Rust test harnesses work that I don't fully understand.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, you probably have some other test (or code called from a test) that hangs when this mutation is inserted. If you look at the corresponding log inside I'm not sure what's happening with nextest reporting a timeout but not stopping. If you can make and share a small repo that shows the behavior then perhaps nextest devs would like to look too.
I'm not sure. One pragmatic thing you can do is just exclude this mutant (or the function containing it), but that's not entirely satisfactory. Another option is to just accept that this mutant causes a timeout, although that does make the mutants run longer and makes the results somewhat inconclusive. Possibly another option is to insert I'm still looking for better answers here. |
Beta Was this translation helpful? Give feedback.
Yes, you probably have some other test (or code called from a test) that hangs when this mutation is inserted. If you look at the corresponding log inside
mutants.out/logs
it might be more clear which one it is -- or, as you already did, just insert the same change by hand.I'm not sure what's happening with nextest reporting a timeout but not stopping. If you can make and share a small repo that shows the behavior then perhaps nextest devs would like to look too.
I'm not sure. One pragmatic thing you can do is just exclude this mutant (or the function containing it), but t…