summaryrefslogtreecommitdiff
path: root/tests/PackageWatchdog
diff options
context:
space:
mode:
authorGavin Corkery <gavincorkery@google.com>2020-03-24 10:43:45 +0000
committerGavin Corkery <gavincorkery@google.com>2020-03-24 23:46:29 +0000
commit007e9df3e12299ff003bae9fd51812ea4eb70b13 (patch)
tree428a6ea8dbebeda8c0ffb6d66a6c673f1b2094f9 /tests/PackageWatchdog
parent887941cbc8384e5d1df077292a98f08f1b54d0d4 (diff)
Preserve failure history when calling startObservingHealth
Instead of always creating a new MonitoredPackage every time PackageWatchdog#startObservingHealth is called, just update the duration of an existing MonitoredPackage if one exists. This means that the failure history will be preserved. Test: atest PackageWatchdogTest Bug: 150114865 Change-Id: I6d6e3e0e893a603fda50df833bc5b6ce1757b6ec
Diffstat (limited to 'tests/PackageWatchdog')
-rw-r--r--tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
index 2957192ecf0f..d011dbbbe5db 100644
--- a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
+++ b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
@@ -1123,6 +1123,28 @@ public class PackageWatchdogTest {
assertThat(testController.getSyncRequests()).isEqualTo(expectedSyncRequests);
}
+ /**
+ * Ensure that the failure history of a package is preserved when making duplicate calls to
+ * observe the package.
+ */
+ @Test
+ public void testFailureHistoryIsPreserved() {
+ PackageWatchdog watchdog = createWatchdog();
+ TestObserver observer = new TestObserver(OBSERVER_NAME_1);
+ watchdog.startObservingHealth(observer, List.of(APP_A), SHORT_DURATION);
+ for (int i = 0; i < PackageWatchdog.DEFAULT_TRIGGER_FAILURE_COUNT - 1; i++) {
+ watchdog.onPackageFailure(List.of(new VersionedPackage(APP_A, VERSION_CODE)),
+ PackageWatchdog.FAILURE_REASON_UNKNOWN);
+ }
+ mTestLooper.dispatchAll();
+ assertThat(observer.mMitigatedPackages).isEmpty();
+ watchdog.startObservingHealth(observer, List.of(APP_A), LONG_DURATION);
+ watchdog.onPackageFailure(List.of(new VersionedPackage(APP_A, VERSION_CODE)),
+ PackageWatchdog.FAILURE_REASON_UNKNOWN);
+ mTestLooper.dispatchAll();
+ assertThat(observer.mMitigatedPackages).isEqualTo(List.of(APP_A));
+ }
+
private void adoptShellPermissions(String... permissions) {
InstrumentationRegistry
.getInstrumentation()