Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java

Issue 2610983002: [Android] Fix subthread native test execution race condition. (Closed)
Patch Set: jcivelli comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
diff --git a/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java b/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
index 4352205a23aa611bda3d7fc587056f336dfc1810..3e27274c40e610295fd5891df874efc58395f5c8 100644
--- a/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
+++ b/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
@@ -128,23 +128,40 @@ public class NativeTest {
}
public void postStart(final Activity activity, boolean forceRunInSubThread) {
+ final Runnable runTestsTask = new Runnable() {
+ @Override
+ public void run() {
+ runTests(activity);
+ }
+ };
+
if (mRunInSubThread || forceRunInSubThread) {
- // Create a new thread and run tests on it.
- new Thread() {
+ // Post a task that posts a task that creates a new thread and runs tests on it.
+
+ // 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
public void run() {
- runTests(activity);
+ new Thread(runTestsTask).start();
}
- }.start();
- } 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(new Runnable() {
+ };
+ final Runnable postTestStarterTask = new Runnable() {
@Override
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);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698