Merge "Deflake InattentiveSleep tests" into rvc-dev

This commit is contained in:
Robert Horvath
2020-03-23 09:05:46 +00:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 14 deletions

View File

@@ -2439,7 +2439,7 @@ public final class PowerManagerService extends SystemService
private boolean isAttentiveTimeoutExpired(long now) { private boolean isAttentiveTimeoutExpired(long now) {
long attentiveTimeout = getAttentiveTimeoutLocked(); long attentiveTimeout = getAttentiveTimeoutLocked();
return attentiveTimeout >= 0 && now > mLastUserActivityTime + attentiveTimeout; return attentiveTimeout >= 0 && now >= mLastUserActivityTime + attentiveTimeout;
} }
/** /**

View File

@@ -63,7 +63,6 @@ import android.os.PowerManager;
import android.os.PowerSaveState; import android.os.PowerSaveState;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.platform.test.annotations.FlakyTest;
import android.provider.Settings; import android.provider.Settings;
import android.service.dreams.DreamManagerInternal; import android.service.dreams.DreamManagerInternal;
import android.test.mock.MockContentResolver; import android.test.mock.MockContentResolver;
@@ -692,7 +691,10 @@ public class PowerManagerServiceTest {
@Test @Test
public void testInattentiveSleep_hideWarningIfStayOnIsEnabledAndPluggedIn() throws Exception { public void testInattentiveSleep_hideWarningIfStayOnIsEnabledAndPluggedIn() throws Exception {
setAttentiveTimeout(15000); setMinimumScreenOffTimeoutConfig(5);
setAttentiveWarningDuration(120);
setAttentiveTimeout(100);
Settings.Global.putInt(mContextSpy.getContentResolver(), Settings.Global.putInt(mContextSpy.getContentResolver(),
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC); Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC);
@@ -708,10 +710,10 @@ public class PowerManagerServiceTest {
} }
@Test @Test
public void testInattentive_userActivityDismissesWarning() throws Exception { public void testInattentiveSleep_userActivityDismissesWarning() throws Exception {
setMinimumScreenOffTimeoutConfig(5); setMinimumScreenOffTimeoutConfig(5);
setAttentiveWarningDuration(30); setAttentiveWarningDuration(1900);
setAttentiveTimeout(100); setAttentiveTimeout(2000);
createService(); createService();
startSystem(); startSystem();
@@ -720,7 +722,7 @@ public class PowerManagerServiceTest {
PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0); PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0);
verify(mInattentiveSleepWarningControllerMock, never()).show(); verify(mInattentiveSleepWarningControllerMock, never()).show();
SystemClock.sleep(70); SystemClock.sleep(150);
verify(mInattentiveSleepWarningControllerMock, times(1)).show(); verify(mInattentiveSleepWarningControllerMock, times(1)).show();
verify(mInattentiveSleepWarningControllerMock, never()).dismiss(anyBoolean()); verify(mInattentiveSleepWarningControllerMock, never()).dismiss(anyBoolean());
when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true); when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true);
@@ -733,16 +735,18 @@ public class PowerManagerServiceTest {
@Test @Test
public void testInattentiveSleep_warningHiddenAfterWakingUp() throws Exception { public void testInattentiveSleep_warningHiddenAfterWakingUp() throws Exception {
setMinimumScreenOffTimeoutConfig(5); setMinimumScreenOffTimeoutConfig(5);
setAttentiveWarningDuration(20); setAttentiveWarningDuration(70);
setAttentiveTimeout(30); setAttentiveTimeout(100);
createService(); createService();
startSystem(); startSystem();
SystemClock.sleep(10); SystemClock.sleep(50);
verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).show(); verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).show();
when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true); when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true);
SystemClock.sleep(30); SystemClock.sleep(70);
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
forceAwake(); forceAwake();
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).dismiss(false); verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).dismiss(false);
} }
@@ -764,7 +768,6 @@ public class PowerManagerServiceTest {
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
} }
@FlakyTest
@Test @Test
public void testInattentiveSleep_goesToSleepWithWakeLock() throws Exception { public void testInattentiveSleep_goesToSleepWithWakeLock() throws Exception {
final String pkg = mContextSpy.getOpPackageName(); final String pkg = mContextSpy.getOpPackageName();
@@ -772,7 +775,7 @@ public class PowerManagerServiceTest {
final String tag = "sleep_testWithWakeLock"; final String tag = "sleep_testWithWakeLock";
setMinimumScreenOffTimeoutConfig(5); setMinimumScreenOffTimeoutConfig(5);
setAttentiveTimeout(10); setAttentiveTimeout(30);
createService(); createService();
startSystem(); startSystem();
@@ -780,7 +783,7 @@ public class PowerManagerServiceTest {
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg, PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg,
null /* workSource */, null /* historyTag */); null /* workSource */, null /* historyTag */);
SystemClock.sleep(11); SystemClock.sleep(60);
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
} }