Update rollback tests for new behaviour that abandons other staged sessions.

This updates RollbackManagerHostTest to account for the amended behaviour
where all other (non-rollback) staged sessions are failed when a rollback
is staged.

Bug: 163734200
Test: atest RollbackManagerHostTest
Change-Id: If26965aba507dfb6754a7afb2f4be9ed0b25b079
diff --git a/hostsidetests/rollback/app/src/com/android/cts/rollback/host/app/HostTestHelper.java b/hostsidetests/rollback/app/src/com/android/cts/rollback/host/app/HostTestHelper.java
index 156980a..a34da7b 100644
--- a/hostsidetests/rollback/app/src/com/android/cts/rollback/host/app/HostTestHelper.java
+++ b/hostsidetests/rollback/app/src/com/android/cts/rollback/host/app/HostTestHelper.java
@@ -644,14 +644,14 @@
     }
 
     @Test
-    public void testRollbackFailsBlockingSessions_Phase1_Install() throws Exception {
+    public void testRollbackFailsOtherSessions_Phase1_Install() throws Exception {
         assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1);
         Install.single(TestApp.A1).commit();
         Install.single(TestApp.A2).setStaged().setEnableRollback().commit();
     }
 
     @Test
-    public void testRollbackFailsBlockingSessions_Phase2_RollBack() throws Exception {
+    public void testRollbackFailsOtherSessions_Phase2_RollBack() throws Exception {
         assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
         InstallUtils.processUserData(TestApp.A);
         // Stage session for package A to check if it can block rollback of A
@@ -659,7 +659,7 @@
 
         // Stage another package not related to the rollback
         Install.single(TestApp.B1).commit();
-        Install.single(TestApp.B2).setStaged().setEnableRollback().commit();
+        final int sessionIdB = Install.single(TestApp.B2).setStaged().setEnableRollback().commit();
 
         final RollbackInfo available = RollbackUtils.getAvailableRollback(TestApp.A);
         RollbackUtils.rollback(available.getRollbackId(), TestApp.A2);
@@ -676,13 +676,18 @@
         assertThat(sessionA).isNotNull();
         assertThat(sessionA.isStagedSessionFailed()).isTrue();
 
+        // Assert that the unrelated staged session is also failed
+        final PackageInstaller.SessionInfo sessionB = InstallUtils.getStagedSessionInfo(sessionIdB);
+        assertThat(sessionB).isNotNull();
+        assertThat(sessionB.isStagedSessionFailed()).isTrue();
+
         // Note: The app is not rolled back until after the rollback is staged
         // and the device has been rebooted.
         assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
     }
 
     @Test
-    public void testRollbackFailsBlockingSessions_Phase3_Confirm() throws Exception {
+    public void testRollbackFailsOtherSessions_Phase3_Confirm() throws Exception {
         // Process TestApp.A
         assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
         InstallUtils.processUserData(TestApp.A);
@@ -693,8 +698,69 @@
         assertThat(committed).causePackagesContainsExactly(TestApp.A2);
         assertThat(committed.getCommittedSessionId()).isNotEqualTo(-1);
 
-        // Assert that unrelated package were not effected
+        // Assert that unrelated package was also failed
+        assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
+    }
+
+    @Test
+    public void testSimultaneousRollbacksBothSucceed_Phase1_Install() throws Exception {
+        assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1);
+        assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(-1);
+        Install.single(TestApp.A1).commit();
+        Install.single(TestApp.A2).setStaged().setEnableRollback().commit();
+        Install.single(TestApp.B1).commit();
+        Install.single(TestApp.B2).setStaged().setEnableRollback().commit();
+    }
+
+    @Test
+    public void testSimultaneousRollbacksBothSucceed_Phase2_RollBack() throws Exception {
+        assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
         assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
+        InstallUtils.processUserData(TestApp.A);
+        InstallUtils.processUserData(TestApp.B);
+
+        final RollbackInfo available = RollbackUtils.getAvailableRollback(TestApp.A);
+        RollbackUtils.rollback(available.getRollbackId(), TestApp.A2);
+        final RollbackInfo committed = RollbackUtils.getCommittedRollback(TestApp.A);
+        assertThat(committed).hasRollbackId(available.getRollbackId());
+        assertThat(committed).isStaged();
+        assertThat(committed).packagesContainsExactly(
+                Rollback.from(TestApp.A2).to(TestApp.A1));
+        assertThat(committed).causePackagesContainsExactly(TestApp.A2);
+        assertThat(committed.getCommittedSessionId()).isNotEqualTo(-1);
+
+        final RollbackInfo availableB = RollbackUtils.getAvailableRollback(TestApp.B);
+        RollbackUtils.rollback(availableB.getRollbackId(), TestApp.B2);
+        final RollbackInfo committedB = RollbackUtils.getCommittedRollback(TestApp.B);
+        assertThat(committedB).hasRollbackId(availableB.getRollbackId());
+        assertThat(committedB).isStaged();
+        assertThat(committedB).packagesContainsExactly(
+                Rollback.from(TestApp.B2).to(TestApp.B1));
+        assertThat(committedB).causePackagesContainsExactly(TestApp.B2);
+        assertThat(committedB.getCommittedSessionId()).isNotEqualTo(-1);
+    }
+
+    @Test
+    public void testSimultaneousRollbacksBothSucceed_Phase3_Confirm() throws Exception {
+        // Process TestApp.A
+        assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
+        InstallUtils.processUserData(TestApp.A);
+        final RollbackInfo committed = RollbackUtils.getCommittedRollback(TestApp.A);
+        assertThat(committed).isStaged();
+        assertThat(committed).packagesContainsExactly(
+                Rollback.from(TestApp.A2).to(TestApp.A1));
+        assertThat(committed).causePackagesContainsExactly(TestApp.A2);
+        assertThat(committed.getCommittedSessionId()).isNotEqualTo(-1);
+
+        // Process TestApp.B
+        assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
+        InstallUtils.processUserData(TestApp.B);
+        final RollbackInfo committedB = RollbackUtils.getCommittedRollback(TestApp.B);
+        assertThat(committedB).isStaged();
+        assertThat(committedB).packagesContainsExactly(
+                Rollback.from(TestApp.B2).to(TestApp.B1));
+        assertThat(committedB).causePackagesContainsExactly(TestApp.B2);
+        assertThat(committedB.getCommittedSessionId()).isNotEqualTo(-1);
     }
 
     /**
diff --git a/hostsidetests/rollback/src/com/android/cts/rollback/host/RollbackManagerHostTest.java b/hostsidetests/rollback/src/com/android/cts/rollback/host/RollbackManagerHostTest.java
index 7191353..f373d47 100644
--- a/hostsidetests/rollback/src/com/android/cts/rollback/host/RollbackManagerHostTest.java
+++ b/hostsidetests/rollback/src/com/android/cts/rollback/host/RollbackManagerHostTest.java
@@ -221,15 +221,30 @@
      * Tests that existing staged sessions are failed when rollback is committed
      */
     @Test
-    public void testRollbackFailsBlockingSessions() throws Exception {
+    public void testRollbackFailsOtherSessions() throws Exception {
         assumeTrue("Device does not support file-system checkpoint",
                 mHostUtils.isCheckpointSupported());
 
-        run("testRollbackFailsBlockingSessions_Phase1_Install");
+        run("testRollbackFailsOtherSessions_Phase1_Install");
         getDevice().reboot();
-        run("testRollbackFailsBlockingSessions_Phase2_RollBack");
+        run("testRollbackFailsOtherSessions_Phase2_RollBack");
         getDevice().reboot();
-        run("testRollbackFailsBlockingSessions_Phase3_Confirm");
+        run("testRollbackFailsOtherSessions_Phase3_Confirm");
+    }
+
+    /**
+     * Tests that simultaneous rollbacks both succeed - neither causes the other to fail.
+     */
+    @Test
+    public void testSimultaneousRollbacksBothSucceed() throws Exception {
+        assumeTrue("Device does not support file-system checkpoint",
+                mHostUtils.isCheckpointSupported());
+
+        run("testSimultaneousRollbacksBothSucceed_Phase1_Install");
+        getDevice().reboot();
+        run("testSimultaneousRollbacksBothSucceed_Phase2_RollBack");
+        getDevice().reboot();
+        run("testSimultaneousRollbacksBothSucceed_Phase3_Confirm");
     }
 
     /**