Skip to content

Fix spurious test failure with panic=abort #113568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions tests/ui/panic-handler/weak-lang-item-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

extern crate weak_lang_items as other;

use std::thread;

fn main() {
let _ = thread::spawn(move|| {
let _ = std::thread::spawn(move || {
// The goal of the test is just to make sure other::foo() is called. Since the function
// panics, it's executed in its own thread. That way, the panic is isolated within the
// thread and wont't affect the overall exit code.
//
// That causes a spurious failures in panic=abort targets though: if the program exits
// before the thread is fully initialized the test will pass, but if the thread gets
// executed first the whole program will abort. Adding a 60 seconds sleep will (hopefully!)
// ensure the program always exits before the thread is executed.
std::thread::sleep(std::time::Duration::from_secs(60));

other::foo()
});
}