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
This commit is contained in:
tonihei 2018-11-21 07:41:27 -08:00 committed by Oliver Woodman
parent dd47bfffb0
commit fd2f8eaba8

View File

@ -99,7 +99,7 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
* is exceeded then the test will fail. * is exceeded then the test will fail.
*/ */
public void runTest(HostedTest hostedTest, long timeoutMs) { 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 hostedTest The test to execute.
* @param timeoutMs The number of milliseconds to wait for the test to finish. * @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.checkArgument(timeoutMs > 0);
Assertions.checkState(Thread.currentThread() != getMainLooper().getThread()); Assertions.checkState(Thread.currentThread() != getMainLooper().getThread());
Assertions.checkState(this.hostedTest == null); Assertions.checkState(this.hostedTest == null);
@ -128,7 +130,9 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
String message = String message =
"Test failed to start. Display may be turned off or keyguard may be present."; "Test failed to start. Display may be turned off or keyguard may be present.";
Log.e(TAG, message); Log.e(TAG, message);
fail(message); if (failOnTimeoutOrForceStop) {
fail(message);
}
} }
if (hostedTest.blockUntilStopped(timeoutMs)) { 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 " String message = "Test force stopped. Activity may have been paused whilst "
+ "test was in progress."; + "test was in progress.";
Log.e(TAG, message); Log.e(TAG, message);
fail(message); if (failOnTimeoutOrForceStop) {
fail(message);
}
} }
} else { } else {
runOnUiThread(hostedTest::forceStop); runOnUiThread(hostedTest::forceStop);
String message = "Test timed out after " + timeoutMs + " ms."; String message = "Test timed out after " + timeoutMs + " ms.";
Log.e(TAG, message); Log.e(TAG, message);
if (failOnTimeout) { if (failOnTimeoutOrForceStop) {
fail(message); fail(message);
} }
} }
@ -234,5 +240,4 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
forcedStopped = hostedTest.forceStop(); forcedStopped = hostedTest.forceStop();
} }
} }
} }