From 8e38f4c380214966b179223d2cc27fa90678ea1a Mon Sep 17 00:00:00 2001 From: Brett Chabot Date: Thu, 11 May 2023 21:17:57 -0700 Subject: [PATCH] Attempt to deflake ScreenUndimDetectorTest by flushing main looper on setup and teardown. Bug: 280970411 Test: atest FrameworksMockingServicesTests:com.android.server.power.ScreenUndimDetectorTest -- --abi x86_64 Change-Id: Ic73036b8eb3d850fc7d95c230d14ecec7c5a8297 --- .../android/server/power/ScreenUndimDetectorTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java b/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java index 93a1f30bbcf0b..43f77bfb4c95f 100644 --- a/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java @@ -38,13 +38,13 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.modules.utils.testing.TestableDeviceConfig; +import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.List; @@ -86,7 +86,7 @@ public class ScreenUndimDetectorTest { @Before public void setup() { - MockitoAnnotations.initMocks(this); + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); DeviceConfig.setProperty(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_UNDIMS_REQUIRED, @@ -100,6 +100,11 @@ public class ScreenUndimDetectorTest { mScreenUndimDetector.systemReady(sContext); } + @After + public void tearDown() { + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + } + @Test public void recordScreenPolicy_disabledByFlag_noop() { DeviceConfig.setProperty(NAMESPACE_ATTENTION_MANAGER_SERVICE,