Commit ff829858 authored by jbudorick's avatar jbudorick Committed by Commit bot

[Android] Fix subthread native test execution race condition.

On L and M, the system posts a task to the main thread after start() returns
that prints a few lines to stdout. Our existing subthread execution model
allowed the tests to run at the same time as this task, resulting in the
task's output interfering with the tests' output.

This change tweaks our subthread test launching logic to post a task to the
main thread that posts another task to the main thread that launches the test
subthread. This should ensure that the system task gets executed before we
start running tests.

BUG=678146

Review-Url: https://codereview.chromium.org/2610983002
Cr-Commit-Position: refs/heads/master@{#441458}
parent a5c72b04
...@@ -128,23 +128,40 @@ public class NativeTest { ...@@ -128,23 +128,40 @@ public class NativeTest {
} }
public void postStart(final Activity activity, boolean forceRunInSubThread) { public void postStart(final Activity activity, boolean forceRunInSubThread) {
final Runnable runTestsTask = new Runnable() {
@Override
public void run() {
runTests(activity);
}
};
if (mRunInSubThread || forceRunInSubThread) { if (mRunInSubThread || forceRunInSubThread) {
// Create a new thread and run tests on it. // Post a task that posts a task that creates a new thread and runs tests on it.
new Thread() {
// On L and M, the system posts a task to the main thread that prints to stdout
// from android::Layout (https://goo.gl/vZA38p). Chaining the subthread creation
// through multiple tasks executed on the main thread ensures that this task
// runs before we start running tests s.t. its output doesn't interfere with
// the test output. See crbug.com/678146 for additional context.
final Handler handler = new Handler();
final Runnable startTestThreadTask = new Runnable() {
@Override @Override
public void run() { public void run() {
runTests(activity); new Thread(runTestsTask).start();
} }
}.start(); };
} else { final Runnable postTestStarterTask = new Runnable() {
// Post a task to run the tests. This allows us to not block
// onCreate and still run tests on the main thread.
new Handler().post(new Runnable() {
@Override @Override
public void run() { public void run() {
runTests(activity); handler.post(startTestThreadTask);
} }
}); };
handler.post(postTestStarterTask);
} else {
// Post a task to run the tests. This allows us to not block
// onCreate and still run tests on the main thread.
new Handler().post(runTestsTask);
} }
} }
......
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 to comment