diff options
| author | 2019-09-26 01:49:34 +0000 | |
|---|---|---|
| committer | 2019-09-26 01:49:34 +0000 | |
| commit | d9f17f81a5431ec2306ef8d2f1d54e7e865b6e02 (patch) | |
| tree | b01b3d4abc1ef345e7e021ff873987754994e463 | |
| parent | 4930a37c52bce631b5f82a018bfded8fdca80607 (diff) | |
| parent | b94686bce5e3f3bee6ad9f4273aeea3ca55217c5 (diff) | |
Merge "Fix testExplicitHealthCheckFailureBeforeExpiry"
| -rw-r--r-- | tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java index 79f5095010e8..06b58fda5b7d 100644 --- a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java +++ b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java @@ -626,11 +626,40 @@ public class PackageWatchdogTest { // Verify that health check is failed assertThat(observer.mMitigatedPackages).containsExactly(APP_A); - // Then clear failed packages and start observing a random package so requests are synced - // and PackageWatchdog#onSupportedPackages is called and APP_A has a chance to fail again - // this time due to package expiry. + // Clear failed packages and forward time to expire the observation duration observer.mMitigatedPackages.clear(); - watchdog.startObservingHealth(observer, Arrays.asList(APP_B), LONG_DURATION); + moveTimeForwardAndDispatch(LONG_DURATION); + + // Verify that health check failure is not notified again + assertThat(observer.mMitigatedPackages).isEmpty(); + } + + /** + * Tests failure when health check duration is different from package observation duration + * Failure is also notified only once. + */ + @Test + public void testExplicitHealthCheckFailureAfterExpiry() { + TestController controller = new TestController(); + PackageWatchdog watchdog = createWatchdog(controller, true /* withPackagesReady */); + TestObserver observer = new TestObserver(OBSERVER_NAME_1, + PackageHealthObserverImpact.USER_IMPACT_MEDIUM); + + // Start observing with explicit health checks for APP_A and + // package observation duration == SHORT_DURATION / 2 + // health check duration == SHORT_DURATION (set by default in the TestController) + controller.setSupportedPackages(Arrays.asList(APP_A)); + watchdog.startObservingHealth(observer, Arrays.asList(APP_A), SHORT_DURATION / 2); + + // Forward time to expire the observation duration + moveTimeForwardAndDispatch(SHORT_DURATION / 2); + + // Verify that health check is failed + assertThat(observer.mMitigatedPackages).containsExactly(APP_A); + + // Clear failed packages and forward time to expire the health check duration + observer.mMitigatedPackages.clear(); + moveTimeForwardAndDispatch(SHORT_DURATION); // Verify that health check failure is not notified again assertThat(observer.mMitigatedPackages).isEmpty(); |