Vertify the exact interactions with mocking object
There are more than 1 interaction inside verifySetupPlatformVpn.
The original code does not actually wait for the target
interaction with Executor.schedule(). The interact may happen
after reset the mocking object. This will leave a unexpected
interaction in the follow up verification and cause a flaky
test.
This test was fine in the initial patch, but becomes failed
after the time unit used in Executor.schedule() was changed
to milliseconds for data stall recovery. Both interactions
for data stall ones and non-data stall ones will be captured
together after that.
Bug: 289961869
Test: atest VpnTest --rerun-until-failure 20
Change-Id: If24e323b366bb15b81fe9fa554fa7ccc852ba6f1
diff --git a/tests/unit/java/com/android/server/connectivity/VpnTest.java b/tests/unit/java/com/android/server/connectivity/VpnTest.java
index 7829cb6..9ae727d 100644
--- a/tests/unit/java/com/android/server/connectivity/VpnTest.java
+++ b/tests/unit/java/com/android/server/connectivity/VpnTest.java
@@ -1965,7 +1965,16 @@
vpn.startVpnProfile(TEST_VPN_PKG);
final NetworkCallback nwCb = triggerOnAvailableAndGetCallback(underlyingNetworkCaps);
- verify(mExecutor, atLeastOnce()).schedule(any(Runnable.class), anyLong(), any());
+ // There are 4 interactions with the executor.
+ // - Network available
+ // - LP change
+ // - NC change
+ // - schedule() calls in scheduleStartIkeSession()
+ // The first 3 calls are triggered from Executor.execute(). The execute() will also call to
+ // schedule() with 0 delay. Verify the exact interaction here so that it won't cause flakes
+ // in the follow-up flow.
+ verify(mExecutor, timeout(TEST_TIMEOUT_MS).times(4))
+ .schedule(any(Runnable.class), anyLong(), any());
reset(mExecutor);
// Mock the setup procedure by firing callbacks