diff options
| author | lucaslin <lucaslin@google.com> | 2022-06-07 16:28:47 +0800 |
|---|---|---|
| committer | Cherrypicker Worker <android-build-cherrypicker-worker@google.com> | 2022-06-10 03:23:56 +0000 |
| commit | bfa19e0c78fb9c515b51e8e5f04b5eb13b0d0c31 (patch) | |
| tree | 8c0d3ecf3ff59ce153a556ac1b32a2504e4fdb38 /tests/unit/java/com/android/server/connectivity/VpnTest.java | |
| parent | e898e26c02e5f40a06d4967256c77814522c6462 (diff) | |
Test recoverable Ikev2 errors
Test if retry mechanism is working or not when there is a
recoverable Ikev2 error.
Bug: 229350078
Test: atest FrameworksNetTests:VpnTest
Change-Id: I5e881c6b42aeb98adce598587e2a7e49be7d9643
(cherry picked from commit adb56e94a5fc3c61af10780713f0b7a4f163c965)
Merged-In: I5e881c6b42aeb98adce598587e2a7e49be7d9643
Diffstat (limited to 'tests/unit/java/com/android/server/connectivity/VpnTest.java')
| -rw-r--r-- | tests/unit/java/com/android/server/connectivity/VpnTest.java | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/tests/unit/java/com/android/server/connectivity/VpnTest.java b/tests/unit/java/com/android/server/connectivity/VpnTest.java index eb35469a43..cdfa1904de 100644 --- a/tests/unit/java/com/android/server/connectivity/VpnTest.java +++ b/tests/unit/java/com/android/server/connectivity/VpnTest.java @@ -1315,7 +1315,7 @@ public class VpnTest { config -> Arrays.asList(config.flags).contains(flag))); } - private void setupPlatformVpnWithSpecificExceptionAndItsErrorCode(IkeException exception, + private void doTestPlatformVpnWithException(IkeException exception, String category, int errorType, int errorCode) throws Exception { final ArgumentCaptor<IkeSessionCallback> captor = ArgumentCaptor.forClass(IkeSessionCallback.class); @@ -1333,6 +1333,7 @@ public class VpnTest { // state verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS)) .createIkeSession(any(), any(), any(), any(), captor.capture(), any()); + reset(mIkev2SessionCreator); final IkeSessionCallback ikeCb = captor.getValue(); ikeCb.onClosedWithException(exception); @@ -1342,6 +1343,23 @@ public class VpnTest { if (errorType == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) { verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS)) .unregisterNetworkCallback(eq(cb)); + } else if (errorType == VpnManager.ERROR_CLASS_RECOVERABLE) { + // To prevent spending much time to test the retry function, only retry 2 times here. + int retryIndex = 0; + verify(mIkev2SessionCreator, + timeout(((TestDeps) vpn.mDeps).getNextRetryDelaySeconds(retryIndex++) * 1000 + + TEST_TIMEOUT_MS)) + .createIkeSession(any(), any(), any(), any(), captor.capture(), any()); + + // Capture a new IkeSessionCallback to get the latest token. + reset(mIkev2SessionCreator); + final IkeSessionCallback ikeCb2 = captor.getValue(); + ikeCb2.onClosedWithException(exception); + verify(mIkev2SessionCreator, + timeout(((TestDeps) vpn.mDeps).getNextRetryDelaySeconds(retryIndex++) * 1000 + + TEST_TIMEOUT_MS)) + .createIkeSession(any(), any(), any(), any(), captor.capture(), any()); + reset(mIkev2SessionCreator); } } @@ -1350,7 +1368,7 @@ public class VpnTest { final IkeProtocolException exception = mock(IkeProtocolException.class); final int errorCode = IkeProtocolException.ERROR_TYPE_AUTHENTICATION_FAILED; when(exception.getErrorType()).thenReturn(errorCode); - setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception, + doTestPlatformVpnWithException(exception, VpnManager.CATEGORY_EVENT_IKE_ERROR, VpnManager.ERROR_CLASS_NOT_RECOVERABLE, errorCode); } @@ -1360,7 +1378,7 @@ public class VpnTest { final IkeProtocolException exception = mock(IkeProtocolException.class); final int errorCode = IkeProtocolException.ERROR_TYPE_TEMPORARY_FAILURE; when(exception.getErrorType()).thenReturn(errorCode); - setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception, + doTestPlatformVpnWithException(exception, VpnManager.CATEGORY_EVENT_IKE_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE, errorCode); } @@ -1370,7 +1388,7 @@ public class VpnTest { final UnknownHostException unknownHostException = new UnknownHostException(); final int errorCode = VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST; when(exception.getCause()).thenReturn(unknownHostException); - setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception, + doTestPlatformVpnWithException(exception, VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE, errorCode); } @@ -1382,7 +1400,7 @@ public class VpnTest { new IkeTimeoutException("IkeTimeoutException"); final int errorCode = VpnManager.ERROR_CODE_NETWORK_PROTOCOL_TIMEOUT; when(exception.getCause()).thenReturn(ikeTimeoutException); - setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception, + doTestPlatformVpnWithException(exception, VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE, errorCode); } @@ -1391,7 +1409,7 @@ public class VpnTest { public void testStartPlatformVpnFailedWithIkeNetworkLostException() throws Exception { final IkeNetworkLostException exception = new IkeNetworkLostException( new Network(100)); - setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception, + doTestPlatformVpnWithException(exception, VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE, VpnManager.ERROR_CODE_NETWORK_LOST); } @@ -1402,7 +1420,7 @@ public class VpnTest { final IOException ioException = new IOException(); final int errorCode = VpnManager.ERROR_CODE_NETWORK_IO; when(exception.getCause()).thenReturn(ioException); - setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception, + doTestPlatformVpnWithException(exception, VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE, errorCode); } @@ -1694,6 +1712,11 @@ public class VpnTest { public DeviceIdleInternal getDeviceIdleInternal() { return mDeviceIdleInternal; } + + public long getNextRetryDelaySeconds(int retryCount) { + // Simply return retryCount as the delay seconds for retrying. + return retryCount; + } } /** |
