Deflake InattentiveSleep tests
Some inattentive sleep tests showed flakiness because of timing issues. Adjusting sleeps helps increase chance scheduled messages have been handled. The change in PowerManagerService is for the case when now == mLastUserActivityTime + attentiveTimeout. updateAttentiveStateLocked considered this time as time to go to sleep, but isAttentiveTimeoutExpired would report false for another millisecond as it used > comparison instead of >= comparison. Bug: 149340215 Test: atest --iterations 200 PowerManagerServiceTest#testInattentive* Change-Id: Ibe5168664c1e01c6e480610686e19573c8df6c6f
This commit is contained in:
@@ -2432,7 +2432,7 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
private boolean isAttentiveTimeoutExpired(long now) {
|
||||
long attentiveTimeout = getAttentiveTimeoutLocked();
|
||||
return attentiveTimeout >= 0 && now > mLastUserActivityTime + attentiveTimeout;
|
||||
return attentiveTimeout >= 0 && now >= mLastUserActivityTime + attentiveTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,7 +63,6 @@ import android.os.PowerManager;
|
||||
import android.os.PowerSaveState;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.FlakyTest;
|
||||
import android.provider.Settings;
|
||||
import android.service.dreams.DreamManagerInternal;
|
||||
import android.test.mock.MockContentResolver;
|
||||
@@ -682,7 +681,10 @@ public class PowerManagerServiceTest {
|
||||
|
||||
@Test
|
||||
public void testInattentiveSleep_hideWarningIfStayOnIsEnabledAndPluggedIn() throws Exception {
|
||||
setAttentiveTimeout(15000);
|
||||
setMinimumScreenOffTimeoutConfig(5);
|
||||
setAttentiveWarningDuration(120);
|
||||
setAttentiveTimeout(100);
|
||||
|
||||
Settings.Global.putInt(mContextSpy.getContentResolver(),
|
||||
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC);
|
||||
|
||||
@@ -698,10 +700,10 @@ public class PowerManagerServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInattentive_userActivityDismissesWarning() throws Exception {
|
||||
public void testInattentiveSleep_userActivityDismissesWarning() throws Exception {
|
||||
setMinimumScreenOffTimeoutConfig(5);
|
||||
setAttentiveWarningDuration(30);
|
||||
setAttentiveTimeout(100);
|
||||
setAttentiveWarningDuration(1900);
|
||||
setAttentiveTimeout(2000);
|
||||
|
||||
createService();
|
||||
startSystem();
|
||||
@@ -710,7 +712,7 @@ public class PowerManagerServiceTest {
|
||||
PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0);
|
||||
verify(mInattentiveSleepWarningControllerMock, never()).show();
|
||||
|
||||
SystemClock.sleep(70);
|
||||
SystemClock.sleep(150);
|
||||
verify(mInattentiveSleepWarningControllerMock, times(1)).show();
|
||||
verify(mInattentiveSleepWarningControllerMock, never()).dismiss(anyBoolean());
|
||||
when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true);
|
||||
@@ -723,16 +725,18 @@ public class PowerManagerServiceTest {
|
||||
@Test
|
||||
public void testInattentiveSleep_warningHiddenAfterWakingUp() throws Exception {
|
||||
setMinimumScreenOffTimeoutConfig(5);
|
||||
setAttentiveWarningDuration(20);
|
||||
setAttentiveTimeout(30);
|
||||
setAttentiveWarningDuration(70);
|
||||
setAttentiveTimeout(100);
|
||||
|
||||
createService();
|
||||
startSystem();
|
||||
SystemClock.sleep(10);
|
||||
SystemClock.sleep(50);
|
||||
verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).show();
|
||||
when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true);
|
||||
SystemClock.sleep(30);
|
||||
SystemClock.sleep(70);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
|
||||
forceAwake();
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).dismiss(false);
|
||||
}
|
||||
|
||||
@@ -754,7 +758,6 @@ public class PowerManagerServiceTest {
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
|
||||
}
|
||||
|
||||
@FlakyTest
|
||||
@Test
|
||||
public void testInattentiveSleep_goesToSleepWithWakeLock() throws Exception {
|
||||
final String pkg = mContextSpy.getOpPackageName();
|
||||
@@ -762,7 +765,7 @@ public class PowerManagerServiceTest {
|
||||
final String tag = "sleep_testWithWakeLock";
|
||||
|
||||
setMinimumScreenOffTimeoutConfig(5);
|
||||
setAttentiveTimeout(10);
|
||||
setAttentiveTimeout(30);
|
||||
createService();
|
||||
startSystem();
|
||||
|
||||
@@ -770,7 +773,7 @@ public class PowerManagerServiceTest {
|
||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg,
|
||||
null /* workSource */, null /* historyTag */);
|
||||
|
||||
SystemClock.sleep(11);
|
||||
SystemClock.sleep(60);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user