about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2023-07-11 11:27:51 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2023-07-11 12:04:31 +0200
commitd8fb568cf4889ec830e8b092cddc24b7d1c29a34 (patch)
tree93d287705209c9e1b827ce43005f888bdece7ec1
parentaf9df2fd91434e5d6fab43a71cf90cc459ea2ad8 (diff)
downloadrust-d8fb568cf4889ec830e8b092cddc24b7d1c29a34.tar.gz
rust-d8fb568cf4889ec830e8b092cddc24b7d1c29a34.zip
fix spurious test failure with panic=abort
-rw-r--r--tests/ui/panic-handler/weak-lang-item-2.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/tests/ui/panic-handler/weak-lang-item-2.rs b/tests/ui/panic-handler/weak-lang-item-2.rs
index a429d8fabc7..6d6e8e04b05 100644
--- a/tests/ui/panic-handler/weak-lang-item-2.rs
+++ b/tests/ui/panic-handler/weak-lang-item-2.rs
@@ -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()
     });
 }