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
This commit is contained in:
Rubin Xu
2019-05-14 16:10:03 +01:00
parent c3c30eefb2
commit 340e5bac48
3 changed files with 9 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -163,5 +163,4 @@ public class LockSettingsServiceTestable extends LockSettingsService {
}
return storedData;
}
}

View File

@@ -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);