summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChiachang Wang <chiachangwang@google.com>2022-04-07 17:25:34 +0800
committerChiachang Wang <chiachangwang@google.com>2022-04-08 08:38:55 +0000
commit44b8a2e8719d33f0fd501dd7fa9333c27e4084ff (patch)
tree2b0aa6603284ead1548cfc35fe9e32cfe7c48722
parentf74bfaa3bf4aeb79c2b7932dba6e6e176a7c7cdb (diff)
downloadCaptivePortalLogin-44b8a2e8719d33f0fd501dd7fa9333c27e4084ff.tar.gz
Ensure activity state being updated to deflake test
The test cannot get response from the instrimentation and fail the test. The issue may be caused by the race with lock in the test intrumentation code. Ensure activty state being updated to DESTROYED before closing the ActivityScenario. Test: atest ; TH Change-Id: Ib7b7145dd75e66f636c2ba2999c086ffb4b890e9
-rw-r--r--tests/src/com/android/captiveportallogin/CaptivePortalLoginActivityTest.java20
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 {