diff options
author | Chiachang Wang <chiachangwang@google.com> | 2022-04-08 11:03:47 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-08 11:03:47 +0000 |
commit | 31f81cdbde2a01fffaa29e7dc40a53d310ad2bd0 (patch) | |
tree | 75ffcef8c27c91e67954ac543e863a795b39376d | |
parent | 57f2cbdb23fae0561d56f5357efe923fd8ebe1a9 (diff) | |
parent | 44b8a2e8719d33f0fd501dd7fa9333c27e4084ff (diff) | |
download | CaptivePortalLogin-31f81cdbde2a01fffaa29e7dc40a53d310ad2bd0.tar.gz |
Ensure activity state being updated to deflake test am: 44b8a2e871
Original change: https://android-review.googlesource.com/c/platform/packages/modules/CaptivePortalLogin/+/2057251
Change-Id: Ic2e20ca649a5e3c20f2f571852bbb8eb7e1d820c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | tests/src/com/android/captiveportallogin/CaptivePortalLoginActivityTest.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/src/com/android/captiveportallogin/CaptivePortalLoginActivityTest.java b/tests/src/com/android/captiveportallogin/CaptivePortalLoginActivityTest.java index 69942a5..5b3ad76 100644 --- a/tests/src/com/android/captiveportallogin/CaptivePortalLoginActivityTest.java +++ b/tests/src/com/android/captiveportallogin/CaptivePortalLoginActivityTest.java @@ -523,6 +523,16 @@ public class CaptivePortalLoginActivityTest { CaptivePortalLoginActivity.DISMISS_PORTAL_IN_VALIDATED_NETWORK, 0 /* default */)); } + void waitForDestroyedState() throws Exception { + final long startTimeMs = System.currentTimeMillis(); + long currentTimeMs = startTimeMs; + while (mActivityScenario.getState() != DESTROYED + && (currentTimeMs - startTimeMs) < TEST_TIMEOUT_MS) { + Thread.sleep(50); + currentTimeMs = System.currentTimeMillis(); + } + } + @Test public void testNetworkCapabilitiesUpdate() throws Exception { initActivity(TEST_URL); @@ -533,6 +543,11 @@ public class CaptivePortalLoginActivityTest { // NetworkCapabilities updates w/ NET_CAPABILITY_VALIDATED. nc.setCapability(NET_CAPABILITY_VALIDATED, true); notifyValidatedChangedAndDismissed(nc); + + // Workaround to deflake the test. The problem may be caused by a race with lock inside + // InstrumentationActivityInvoker. + // TODO: Remove it once https://github.com/android/android-test/issues/676 is fixed. + waitForDestroyedState(); } @Test @@ -547,6 +562,11 @@ public class CaptivePortalLoginActivityTest { // Enable flag. Auto-dismissed. setDismissPortalInValidatedNetwork(true); notifyValidatedChangedAndDismissed(nc); + + // Workaround to deflake the test. The problem may be caused by a race with lock inside + // InstrumentationActivityInvoker. + // TODO: Remove it once https://github.com/android/android-test/issues/676 is fixed. + waitForDestroyedState(); } private HttpServer runCustomSchemeTest(String linkUri) throws Exception { |