Commit de4ff4c5 by tonihei Committed by Oliver Woodman

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
parent 56ff2ef5
...@@ -101,6 +101,17 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba ...@@ -101,6 +101,17 @@ 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(final HostedTest hostedTest, long timeoutMs) { 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.checkArgument(timeoutMs > 0);
Assertions.checkState(Thread.currentThread() != getMainLooper().getThread()); Assertions.checkState(Thread.currentThread() != getMainLooper().getThread());
...@@ -131,7 +142,11 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba ...@@ -131,7 +142,11 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
} else { } else {
String message = "Test timed out after " + timeoutMs + " ms."; String message = "Test timed out after " + timeoutMs + " ms.";
Log.e(TAG, message); Log.e(TAG, message);
fail(message); if (failOnTimeout) {
fail(message);
}
maybeStopHostedTest();
hostedTestStoppedCondition.block();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment