From 1fce0cfd4de53dd2f5e95747c23385d4bdda50c5 Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Mon, 3 Jul 2023 14:41:58 +0000 Subject: [PATCH] Test: Fix missed latch exceptions. Catch timeouts, and general errors in the case of an InterupptedException. PiperOrigin-RevId: 545219647 --- .../utils/VideoFrameProcessorTestRunner.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java index e7c692dc3d..81f17e46f9 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java @@ -306,6 +306,7 @@ public final class VideoFrameProcessorTestRunner { @Override public void onError(VideoFrameProcessingException exception) { videoFrameProcessingException.set(exception); + checkNotNull(videoFrameProcessingEndedLatch).countDown(); } @Override @@ -376,15 +377,18 @@ public final class VideoFrameProcessorTestRunner { public void endFrameProcessing(long videoFrameProcessingWaitTimeMs) throws InterruptedException { videoFrameProcessor.signalEndOfInput(); + @Nullable Exception endFrameProcessingException = null; try { - checkNotNull(videoFrameProcessingEndedLatch) - .await(videoFrameProcessingWaitTimeMs, MILLISECONDS); + if (!checkNotNull(videoFrameProcessingEndedLatch) + .await(videoFrameProcessingWaitTimeMs, MILLISECONDS)) { + endFrameProcessingException = + new IllegalStateException("Video frame processing timed out."); + } } catch (InterruptedException e) { - // Report videoFrameProcessingException before potentially reporting a timeout - // InterruptedException. - assertThat(videoFrameProcessingException.get()).isNull(); - throw e; + endFrameProcessingException = e; } + assertThat(videoFrameProcessingException.get()).isNull(); + assertThat(endFrameProcessingException).isNull(); } /**