From 0b2497799f0c225a9c279f5a8a3b369cb3545394 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Fri, 2 Feb 2018 09:41:31 -0800 Subject: [PATCH] Interrupt the test thread for uncaught errors This makes assertion errors in code running on the Looper less easy to miss. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=184294290 --- .../com/google/android/exoplayer2/RobolectricUtil.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java b/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java index af2a0ef8c6..0b5740b72c 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java @@ -117,7 +117,14 @@ public final class RobolectricUtil { } } if (!isRemoved) { - target.dispatchMessage(pendingMessage.message); + try { + target.dispatchMessage(pendingMessage.message); + } catch (Throwable t) { + // Interrupt the main thread to terminate the test. Robolectric's HandlerThread will + // print the rethrown error to standard output. + Looper.getMainLooper().getThread().interrupt(); + throw t; + } } } if (Util.SDK_INT >= 21) {