From b5d0907090e6b6730c26b1d67facb40f0bd549d0 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Mon, 18 Oct 2021 10:48:13 +0200 Subject: [PATCH] Get back stack traces and error messages when tests fail (#2758) Before this PR, when a test failed, we often got: ``` thread panicked while processing panic. aborting. error: test failed, to rerun pass '-p deltachat --lib' Caused by: process didn't exit successfully: `/home/user/deltachat-android/jni/deltachat-core-rust/target/debug/deps/deltachat-33648fc4aaad608c 'contact::tests::test_selfavatar_changed_event' --nocapture` (signal: 4, SIGILL: illegal instruction) ``` instead of the error message and stack trace. This PR fixes this. --- src/test_utils.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index ac91be18b..525e42587 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -111,12 +111,15 @@ impl TestContext { let (evtracker_sender, evtracker_receiver) = channel::unbounded(); async_std::task::spawn(async move { - // Make sure that the test fails if there is a panic on this thread here: - let current_id = task::current().id(); + // Make sure that the test fails if there is a panic on this thread here + // (but not if there is a panic on another thread) + let looptask_id = task::current().id(); let orig_hook = panic::take_hook(); panic::set_hook(Box::new(move |panic_info| { - if task::current().id() == current_id { - poison_sender.try_send(panic_info.to_string()).ok(); + if let Some(panicked_task) = task::try_current() { + if panicked_task.id() == looptask_id { + poison_sender.try_send(panic_info.to_string()).ok(); + } } orig_hook(panic_info); }));