test: Notifiy more prominently & in more tests about false positives when running cargo test (#6308)

This PR:
- Moves the note about the false positive to the end of the test output,
where it is more likely to be noticed
- Also notes in test_modify_chat_disordered() and
test_setup_contact_*(), in addition to the existing note in
test_was_seen_recently()
This commit is contained in:
Hocuri
2024-12-06 15:07:57 +01:00
committed by GitHub
parent f03dc6af12
commit 39be59172d
4 changed files with 28 additions and 15 deletions

View File

@@ -1351,6 +1351,24 @@ async fn write_msg(context: &Context, prefix: &str, msg: &Message, buf: &mut Str
.unwrap();
}
/// When dropped after a test failure,
/// prints a note about a possible false-possible caused by SystemTime::shift().
pub(crate) struct TimeShiftFalsePositiveNote;
impl Drop for TimeShiftFalsePositiveNote {
fn drop(&mut self) {
if std::thread::panicking() {
let green = nu_ansi_term::Color::Green.normal();
println!("{}", green.paint(
"\nNOTE: This test failure may be a false-positive, caused by tests running in parallel.
The issue is that `SystemTime::shift()` (a utility function for tests) changes the time for all threads doing tests, and not only for the running test.
Until the false-positive is fixed:
- Use `cargo test -- --test-threads 1` instead of `cargo test`
- Or use `cargo nextest run` (install with `cargo install cargo-nextest --locked`)\n")
);
}
}
}
#[cfg(test)]
mod tests {
use super::*;