Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 340e5bac authored by Rubin Xu's avatar Rubin Xu
Browse files

Fix LockSettingsService unit test flakiness

Flush the unlockUser() call in the handler thread before changing
the device credential again.

Bug: 131132243
Test: atest --generate-new-metrics 100 WeaverBasedSyntheticPasswordTests#testTokenBasedClearPassword
Change-Id: I1fdb5009caf744a7c1893c0e23d307bc9ee366c6
parent c3c30eef
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -235,6 +235,10 @@ public abstract class BaseLockSettingsServiceTests extends AndroidTestCase {
        mPasswordSlotManager.cleanup();
    }

    protected void flushHandlerTasks() {
        mService.mHandler.runWithScissors(() -> { }, 0 /*now*/); // Flush runnables on handler
    }

    protected void assertNotEquals(long expected, long actual) {
        assertTrue(expected != actual);
    }
+0 −1
Original line number Diff line number Diff line
@@ -163,5 +163,4 @@ public class LockSettingsServiceTestable extends LockSettingsService {
        }
        return storedData;
    }

}
+5 −4
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {

        reset(mAuthSecretService);
        mService.onUnlockUser(PRIMARY_USER_ID);
        mService.mHandler.runWithScissors(() -> {}, 0 /*now*/); // Flush runnables on handler
        flushHandlerTasks();
        verify(mAuthSecretService, never()).primaryUserCredential(any(ArrayList.class));
    }

@@ -242,7 +242,7 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {

        reset(mAuthSecretService);
        mService.onUnlockUser(PRIMARY_USER_ID);
        mService.mHandler.runWithScissors(() -> {}, 0 /*now*/); // Flush runnables on handler
        flushHandlerTasks();
        verify(mAuthSecretService, never()).primaryUserCredential(any(ArrayList.class));
    }

@@ -254,7 +254,7 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {

        reset(mAuthSecretService);
        mService.onUnlockUser(PRIMARY_USER_ID);
        mService.mHandler.runWithScissors(() -> {}, 0 /*now*/); // Flush runnables on handler
        flushHandlerTasks();
        verify(mAuthSecretService).primaryUserCredential(any(ArrayList.class));
    }

@@ -357,7 +357,7 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {
                handle, token, PASSWORD_QUALITY_SOMETHING, PRIMARY_USER_ID);

        // Verify DPM gets notified about new device lock
        mService.mHandler.runWithScissors(() -> {}, 0 /*now*/); // Flush runnables on handler
        flushHandlerTasks();
        final PasswordMetrics metric = PasswordMetrics.computeForCredential(
                LockPatternUtils.CREDENTIAL_TYPE_PATTERN, pattern);
        verify(mDevicePolicyManager).setActivePasswordState(metric, PRIMARY_USER_ID);
@@ -384,6 +384,7 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {

        mLocalService.setLockCredentialWithToken(null, LockPatternUtils.CREDENTIAL_TYPE_NONE,
                handle, token, PASSWORD_QUALITY_UNSPECIFIED, PRIMARY_USER_ID);
        flushHandlerTasks(); // flush the unlockUser() call before changing password again
        mLocalService.setLockCredentialWithToken(pattern, LockPatternUtils.CREDENTIAL_TYPE_PATTERN,
                handle, token, PASSWORD_QUALITY_SOMETHING, PRIMARY_USER_ID);