summaryrefslogtreecommitdiff
path: root/tests/testables/src
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2018-07-20 14:52:22 -0400
committerJason Monk <jmonk@google.com>2018-07-20 16:12:46 -0400
commit759e91212ddc4f56c69ea02123f6f77eb2f7ecb8 (patch)
tree57d42ae9b9669a348f344ce00450098ef583d51d /tests/testables/src
parent55f098118c3b4be381d48a94817b923e58b72b21 (diff)
Disable main looper holding
It might make failures more clear Test: runtest systemui Bug: 110417074 Change-Id: I9880998af42016b9d625cc3e890a94b282f49df0
Diffstat (limited to 'tests/testables/src')
-rw-r--r--tests/testables/src/android/testing/TestableInstrumentation.java26
-rw-r--r--tests/testables/src/android/testing/TestableLooper.java12
2 files changed, 24 insertions, 14 deletions
diff --git a/tests/testables/src/android/testing/TestableInstrumentation.java b/tests/testables/src/android/testing/TestableInstrumentation.java
index 3207b486b329..c35dc68e071f 100644
--- a/tests/testables/src/android/testing/TestableInstrumentation.java
+++ b/tests/testables/src/android/testing/TestableInstrumentation.java
@@ -38,22 +38,26 @@ public class TestableInstrumentation extends AndroidJUnitRunner {
@Override
public void onCreate(Bundle arguments) {
- sManager = new MainLooperManager();
- Log.setWtfHandler((tag, what, system) -> {
- if (system) {
- Log.e(TAG, "WTF!!", what);
- } else {
- // These normally kill the app, but we don't want that in a test, instead we want
- // it to throw.
- throw new RuntimeException(what);
- }
- });
+ if (TestableLooper.HOLD_MAIN_THREAD) {
+ sManager = new MainLooperManager();
+ Log.setWtfHandler((tag, what, system) -> {
+ if (system) {
+ Log.e(TAG, "WTF!!", what);
+ } else {
+ // These normally kill the app, but we don't want that in a test, instead we want
+ // it to throw.
+ throw new RuntimeException(what);
+ }
+ });
+ }
super.onCreate(arguments);
}
@Override
public void finish(int resultCode, Bundle results) {
- sManager.destroy();
+ if (TestableLooper.HOLD_MAIN_THREAD) {
+ sManager.destroy();
+ }
super.finish(resultCode, results);
}
diff --git a/tests/testables/src/android/testing/TestableLooper.java b/tests/testables/src/android/testing/TestableLooper.java
index f8d223ab91b6..8b4cba12b0e6 100644
--- a/tests/testables/src/android/testing/TestableLooper.java
+++ b/tests/testables/src/android/testing/TestableLooper.java
@@ -39,6 +39,12 @@ import java.util.Map;
*/
public class TestableLooper {
+ /**
+ * Whether to hold onto the main thread through all tests in an attempt to
+ * catch crashes.
+ */
+ public static final boolean HOLD_MAIN_THREAD = false;
+
private Looper mLooper;
private MessageQueue mQueue;
private MessageHandler mMessageHandler;
@@ -77,7 +83,7 @@ public class TestableLooper {
*/
public void destroy() {
mQueueWrapper.release();
- if (mLooper == Looper.getMainLooper()) {
+ if (HOLD_MAIN_THREAD && mLooper == Looper.getMainLooper()) {
TestableInstrumentation.releaseMain();
}
}
@@ -199,7 +205,7 @@ public class TestableLooper {
}
private static TestLooperManager acquireLooperManager(Looper l) {
- if (l == Looper.getMainLooper()) {
+ if (HOLD_MAIN_THREAD && l == Looper.getMainLooper()) {
TestableInstrumentation.acquireMain();
}
return InstrumentationRegistry.getInstrumentation().acquireLooperManager(l);
@@ -291,7 +297,7 @@ public class TestableLooper {
if (set) {
mTestableLooper.mQueueWrapper.release();
mTestableLooper.mQueueWrapper = null;
- if (mLooper == Looper.getMainLooper()) {
+ if (HOLD_MAIN_THREAD && mLooper == Looper.getMainLooper()) {
TestableInstrumentation.releaseMain();
}
}