From e2e5ee1c3935a1ee66128a1081bedc9ec40f9012 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 11 Jun 2019 23:44:39 +0800 Subject: Fix crash of test after finishing RecentsAnimationTest The scheduleIdleLocked may be called when updating visibility of activity. That will cause a mocked record to be used in unexpected invocations. Also block until the test thread has completed the pending messages to prevent the execution from overlapping with the next test. Fix: 134891465 Test: atest RecentsAnimationTest Change-Id: I339505ee75ba6e67aa8668dd4e40aef0f74df2aa --- .../wmtests/src/com/android/server/wm/ActivityTestsBase.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java index 53b0add8c37e..4986a6d5bd0d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java @@ -585,7 +585,10 @@ class ActivityTestsBase { } void tearDown() { - mHandlerThread.quitSafely(); + // Make sure there are no running messages and then quit the thread so the next test + // won't be affected. + mHandlerThread.getThreadHandler().runWithScissors(mHandlerThread::quit, + 0 /* timeout */); } } @@ -630,7 +633,8 @@ class ActivityTestsBase { mWindowManager = prepareMockWindowManager(); mKeyguardController = mock(KeyguardController.class); - // Do not schedule idle timeouts + // Do not schedule idle that may touch methods outside the scope of the test. + doNothing().when(this).scheduleIdleLocked(); doNothing().when(this).scheduleIdleTimeoutLocked(any()); // unit test version does not handle launch wake lock doNothing().when(this).acquireLaunchWakelock(); -- cgit v1.2.3-59-g8ed1b