Extend HostActivity for reuse and silent timeout.

Added option to fail on timeout. Also reset internals in all cases
such that the activity can be used more than once.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159419176
This commit is contained in:
tonihei 2017-06-19 06:23:22 -07:00 committed by Oliver Woodman
parent 56ff2ef598
commit de4ff4c5ec

View file

@ -101,6 +101,17 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
* is exceeded then the test will fail.
*/
public void runTest(final HostedTest hostedTest, long timeoutMs) {
runTest(hostedTest, timeoutMs, true);
}
/**
* Executes a {@link HostedTest} inside the host.
*
* @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.
*/
public void runTest(final HostedTest hostedTest, long timeoutMs, boolean failOnTimeout) {
Assertions.checkArgument(timeoutMs > 0);
Assertions.checkState(Thread.currentThread() != getMainLooper().getThread());
@ -131,7 +142,11 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
} else {
String message = "Test timed out after " + timeoutMs + " ms.";
Log.e(TAG, message);
fail(message);
if (failOnTimeout) {
fail(message);
}
maybeStopHostedTest();
hostedTestStoppedCondition.block();
}
}