From fd2f8eaba8604bef2c1fadf3e70a2154772790dd Mon Sep 17 00:00:00 2001 From: tonihei Date: Wed, 21 Nov 2018 07:41:27 -0800 Subject: [PATCH] Make ABR playback tests more resilient to HostActivity failures. We currently fail the entire playback tests if we exceed a start timeout or the test gets stopped forcefully. This is problematic as the start timeout may happen from time to time for the ABR tests and we'd still like to have the remaining playbacks. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=222406639 --- .../exoplayer2/testutil/HostActivity.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java index 257b66a3d0..8f2b977f08 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java @@ -99,7 +99,7 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba * is exceeded then the test will fail. */ public void runTest(HostedTest hostedTest, long timeoutMs) { - runTest(hostedTest, timeoutMs, true); + runTest(hostedTest, timeoutMs, /* failOnTimeoutOrForceStop= */ true); } /** @@ -107,9 +107,11 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba * * @param hostedTest The test to execute. * @param timeoutMs The number of milliseconds to wait for the test to finish. - * @param failOnTimeout Whether the test fails when the timeout is exceeded. + * @param failOnTimeoutOrForceStop Whether the test fails when a timeout is exceeded or the test + * is stopped forcefully. */ - public void runTest(final HostedTest hostedTest, long timeoutMs, boolean failOnTimeout) { + public void runTest( + final HostedTest hostedTest, long timeoutMs, boolean failOnTimeoutOrForceStop) { Assertions.checkArgument(timeoutMs > 0); Assertions.checkState(Thread.currentThread() != getMainLooper().getThread()); Assertions.checkState(this.hostedTest == null); @@ -128,7 +130,9 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba String message = "Test failed to start. Display may be turned off or keyguard may be present."; Log.e(TAG, message); - fail(message); + if (failOnTimeoutOrForceStop) { + fail(message); + } } if (hostedTest.blockUntilStopped(timeoutMs)) { @@ -140,13 +144,15 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba String message = "Test force stopped. Activity may have been paused whilst " + "test was in progress."; Log.e(TAG, message); - fail(message); + if (failOnTimeoutOrForceStop) { + fail(message); + } } } else { runOnUiThread(hostedTest::forceStop); String message = "Test timed out after " + timeoutMs + " ms."; Log.e(TAG, message); - if (failOnTimeout) { + if (failOnTimeoutOrForceStop) { fail(message); } } @@ -234,5 +240,4 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba forcedStopped = hostedTest.forceStop(); } } - }