From 62676b0eac636e0729ce1b71dcf49f013e0cc14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Tue, 29 Mar 2022 10:23:30 +0200 Subject: [PATCH] Include background exception in test failure report --- .../mailbox/core/server/IntegrationTest.kt | 11 ++++++----- .../org/briarproject/mailbox/core/setup/WipeTest1.kt | 4 ++-- .../org/briarproject/mailbox/core/setup/WipeTest2.kt | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mailbox-core/src/test/java/org/briarproject/mailbox/core/server/IntegrationTest.kt b/mailbox-core/src/test/java/org/briarproject/mailbox/core/server/IntegrationTest.kt index a628a963..98c0115f 100644 --- a/mailbox-core/src/test/java/org/briarproject/mailbox/core/server/IntegrationTest.kt +++ b/mailbox-core/src/test/java/org/briarproject/mailbox/core/server/IntegrationTest.kt @@ -63,13 +63,13 @@ abstract class IntegrationTest(private val installJsonFeature: Boolean = true) { protected val contact2 = getNewRandomContact() @Volatile - protected var exceptionInBackgroundThread = false + protected var exceptionInBackgroundThread: Throwable? = null init { // Ensure exceptions thrown on worker threads cause tests to fail val fail = Thread.UncaughtExceptionHandler { _: Thread?, throwable: Throwable -> LOG.warn("Caught unhandled exception", throwable) - exceptionInBackgroundThread = true + exceptionInBackgroundThread = throwable } Thread.setDefaultUncaughtExceptionHandler(fail) } @@ -91,7 +91,7 @@ abstract class IntegrationTest(private val installJsonFeature: Boolean = true) { @BeforeEach open fun beforeEach() { - exceptionInBackgroundThread = false + exceptionInBackgroundThread = null // need to reopen database here because we're closing it after each test db.open(null) db.read { txn -> @@ -112,8 +112,9 @@ abstract class IntegrationTest(private val installJsonFeature: Boolean = true) { assertFalse(setupManager.hasDb) } - if (exceptionInBackgroundThread) { - fail("background thread has thrown an exception unexpectedly") + if (exceptionInBackgroundThread != null) { + fail("background thread has thrown an exception unexpectedly", + exceptionInBackgroundThread) } } diff --git a/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest1.kt b/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest1.kt index 11b79b0f..e3c622e8 100644 --- a/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest1.kt +++ b/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest1.kt @@ -20,9 +20,9 @@ class WipeTest1 : IntegrationTest() { t1.join() t2.join() - // reset flag for exceptions thrown on background threads as this can indeed happen here + // reset field for exceptions thrown on background threads as this can indeed happen here // and is OK - exceptionInBackgroundThread = false + exceptionInBackgroundThread = null } @AfterEach diff --git a/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest2.kt b/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest2.kt index 14de328d..dd2256c1 100644 --- a/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest2.kt +++ b/mailbox-core/src/test/java/org/briarproject/mailbox/core/setup/WipeTest2.kt @@ -51,9 +51,9 @@ class WipeTest2 : IntegrationTest() { assertEquals(1, succeeded) assertEquals(1, failed) - // reset flag for exceptions thrown on background threads as this can indeed happen here + // reset field for exceptions thrown on background threads as this can indeed happen here // and is OK - exceptionInBackgroundThread = false + exceptionInBackgroundThread = null } @AfterEach -- GitLab