Commit eea229f2 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

SigninTestUtil: During tear down, wait for AccountHolders to be removed

Without this change, there is a race condition where it's possible that
an auth token gets requested from the native side (via
OAuth2TokenServiceDelegateAndroid) for an account that was actually
already removed, which causes an exception in
FakeAccountManagerDelegate.getAccountHolder.

https://crrev.com/c/1148392 uncovered this, but I believe the race
condition is there independent of that CL (it's just much less likely
to get triggered).

Bug: 856179
Change-Id: I23bdf54aba90b1bbfd64f45963ea32d08b63c852
Reviewed-on: https://chromium-review.googlesource.com/1156688
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579783}
parent 5df3d8df
...@@ -8,6 +8,7 @@ import android.accounts.Account; ...@@ -8,6 +8,7 @@ import android.accounts.Account;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.content.Context; import android.content.Context;
import android.support.annotation.WorkerThread;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
...@@ -44,6 +45,7 @@ public final class SigninTestUtil { ...@@ -44,6 +45,7 @@ public final class SigninTestUtil {
* *
* This must be called before native is loaded. * This must be called before native is loaded.
*/ */
@WorkerThread
public static void setUpAuthForTest(Instrumentation instrumentation) { public static void setUpAuthForTest(Instrumentation instrumentation) {
assert sContext == null; assert sContext == null;
sContext = instrumentation.getTargetContext(); sContext = instrumentation.getTargetContext();
...@@ -63,12 +65,11 @@ public final class SigninTestUtil { ...@@ -63,12 +65,11 @@ public final class SigninTestUtil {
/** /**
* Tears down the test authentication environment. * Tears down the test authentication environment.
*/ */
@WorkerThread
public static void tearDownAuthForTest() { public static void tearDownAuthForTest() {
ThreadUtils.runOnUiThreadBlocking(() -> { for (AccountHolder accountHolder : sAddedAccounts) {
for (AccountHolder accountHolder : sAddedAccounts) { sAccountManager.removeAccountHolderBlocking(accountHolder);
sAccountManager.removeAccountHolderExplicitly(accountHolder); }
}
});
sAddedAccounts.clear(); sAddedAccounts.clear();
sContext = null; sContext = null;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment