Merge "Correct the test design for network lost case"
This commit is contained in:
@@ -1498,8 +1498,18 @@ public class VpnTest extends VpnTestBase {
|
|||||||
verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS))
|
verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS))
|
||||||
.createIkeSession(any(), any(), any(), any(), captor.capture(), any());
|
.createIkeSession(any(), any(), any(), any(), captor.capture(), any());
|
||||||
reset(mIkev2SessionCreator);
|
reset(mIkev2SessionCreator);
|
||||||
final IkeSessionCallback ikeCb = captor.getValue();
|
// For network lost case, the process should be triggered by calling onLost(), which is the
|
||||||
ikeCb.onClosedWithException(exception);
|
// same process with the real case.
|
||||||
|
if (errorCode == VpnManager.ERROR_CODE_NETWORK_LOST) {
|
||||||
|
cb.onLost(TEST_NETWORK);
|
||||||
|
final ArgumentCaptor<Runnable> runnableCaptor =
|
||||||
|
ArgumentCaptor.forClass(Runnable.class);
|
||||||
|
verify(mExecutor).schedule(runnableCaptor.capture(), anyLong(), any());
|
||||||
|
runnableCaptor.getValue().run();
|
||||||
|
} else {
|
||||||
|
final IkeSessionCallback ikeCb = captor.getValue();
|
||||||
|
ikeCb.onClosedWithException(exception);
|
||||||
|
}
|
||||||
|
|
||||||
verifyPowerSaveTempWhitelistApp(TEST_VPN_PKG);
|
verifyPowerSaveTempWhitelistApp(TEST_VPN_PKG);
|
||||||
reset(mDeviceIdleInternal);
|
reset(mDeviceIdleInternal);
|
||||||
@@ -1510,14 +1520,16 @@ public class VpnTest extends VpnTestBase {
|
|||||||
.unregisterNetworkCallback(eq(cb));
|
.unregisterNetworkCallback(eq(cb));
|
||||||
} else if (errorType == VpnManager.ERROR_CLASS_RECOVERABLE) {
|
} else if (errorType == VpnManager.ERROR_CLASS_RECOVERABLE) {
|
||||||
int retryIndex = 0;
|
int retryIndex = 0;
|
||||||
final IkeSessionCallback ikeCb2 = verifyRetryAndGetNewIkeCb(retryIndex++);
|
final IkeSessionCallback ikeCb2 = verifyRetryAndGetNewIkeCb(retryIndex++, errorCode);
|
||||||
|
|
||||||
ikeCb2.onClosedWithException(exception);
|
if (ikeCb2 != null) {
|
||||||
verifyRetryAndGetNewIkeCb(retryIndex++);
|
ikeCb2.onClosedWithException(exception);
|
||||||
|
verifyRetryAndGetNewIkeCb(retryIndex++, errorCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IkeSessionCallback verifyRetryAndGetNewIkeCb(int retryIndex) {
|
private IkeSessionCallback verifyRetryAndGetNewIkeCb(int retryIndex, int errorCode) {
|
||||||
final ArgumentCaptor<Runnable> runnableCaptor =
|
final ArgumentCaptor<Runnable> runnableCaptor =
|
||||||
ArgumentCaptor.forClass(Runnable.class);
|
ArgumentCaptor.forClass(Runnable.class);
|
||||||
final ArgumentCaptor<IkeSessionCallback> ikeCbCaptor =
|
final ArgumentCaptor<IkeSessionCallback> ikeCbCaptor =
|
||||||
@@ -1530,15 +1542,21 @@ public class VpnTest extends VpnTestBase {
|
|||||||
// Mock the event of firing the retry task
|
// Mock the event of firing the retry task
|
||||||
runnableCaptor.getValue().run();
|
runnableCaptor.getValue().run();
|
||||||
|
|
||||||
verify(mIkev2SessionCreator)
|
// Vpn won't retry when there is no usable underlying network.
|
||||||
.createIkeSession(any(), any(), any(), any(), ikeCbCaptor.capture(), any());
|
if (errorCode == VpnManager.ERROR_CODE_NETWORK_LOST) {
|
||||||
|
verify(mIkev2SessionCreator, never())
|
||||||
|
.createIkeSession(any(), any(), any(), any(), ikeCbCaptor.capture(), any());
|
||||||
|
} else {
|
||||||
|
verify(mIkev2SessionCreator)
|
||||||
|
.createIkeSession(any(), any(), any(), any(), ikeCbCaptor.capture(), any());
|
||||||
|
}
|
||||||
|
|
||||||
// Forget the mIkev2SessionCreator#createIkeSession call and mExecutor#schedule call
|
// Forget the mIkev2SessionCreator#createIkeSession call and mExecutor#schedule call
|
||||||
// for the next retry verification
|
// for the next retry verification
|
||||||
resetIkev2SessionCreator(mIkeSessionWrapper);
|
resetIkev2SessionCreator(mIkeSessionWrapper);
|
||||||
resetExecutor(mScheduledFuture);
|
resetExecutor(mScheduledFuture);
|
||||||
|
|
||||||
return ikeCbCaptor.getValue();
|
return (ikeCbCaptor.getAllValues().size() == 0) ? null : ikeCbCaptor.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user