diff --git a/android/test/e2e/build.gradle.kts b/android/test/e2e/build.gradle.kts index 8fb521adaa6b..560d553ff3b3 100644 --- a/android/test/e2e/build.gradle.kts +++ b/android/test/e2e/build.gradle.kts @@ -46,6 +46,7 @@ android { put("clearPackageData", "true") addOptionalPropertyAsArgument("valid_test_account_number") addOptionalPropertyAsArgument("invalid_test_account_number") + addOptionalPropertyAsArgument("ignore_highly_rate_limited_tests") } } diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt index 2efb299246ee..bfcc1181dd35 100644 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt @@ -5,8 +5,8 @@ import net.mullvad.mullvadvpn.test.common.constant.LOGIN_FAILURE_TIMEOUT import net.mullvad.mullvadvpn.test.common.extension.clickAgreeOnPrivacyDisclaimer import net.mullvad.mullvadvpn.test.common.extension.clickAllowOnNotificationPermissionPromptIfApiLevel33AndAbove import net.mullvad.mullvadvpn.test.common.extension.findObjectWithTimeout +import net.mullvad.mullvadvpn.test.e2e.annotations.HighlyRateLimited import net.mullvad.mullvadvpn.test.e2e.misc.AccountTestRule -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension @@ -27,7 +27,7 @@ class LoginTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) { } @Test - @Disabled("Disabled to avoid getting rate-limited.") + @HighlyRateLimited fun testLoginWithInvalidCredentials() { // Given val invalidDummyAccountNumber = accountTestRule.invalidAccountNumber diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/annotations/HighlyRateLimited.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/annotations/HighlyRateLimited.kt new file mode 100644 index 000000000000..0d3609063ae6 --- /dev/null +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/annotations/HighlyRateLimited.kt @@ -0,0 +1,29 @@ +package net.mullvad.mullvadvpn.test.e2e.annotations + +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.jupiter.api.extension.ConditionEvaluationResult +import org.junit.jupiter.api.extension.ExecutionCondition +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.extension.ExtensionContext +import net.mullvad.mullvadvpn.test.e2e.constant.IGNORE_HIGHLY_RATE_LIMITED +import net.mullvad.mullvadvpn.test.e2e.extension.getRequiredArgument + +/** + * Annotation for tests making use of API endpoints/requests that are highly rate limited such as failed login requests. + */ +@Retention(AnnotationRetention.RUNTIME) +@ExtendWith(HighlyRateLimited.ShouldRunWhenSeverelyAffectedByRateLimiting::class) +annotation class HighlyRateLimited { + class ShouldRunWhenSeverelyAffectedByRateLimiting: ExecutionCondition { + override fun evaluateExecutionCondition(context: ExtensionContext?): ConditionEvaluationResult { + val ignoreHighlyRateLimited = InstrumentationRegistry.getArguments().getRequiredArgument( + IGNORE_HIGHLY_RATE_LIMITED).toBoolean() + + if (ignoreHighlyRateLimited) { + return ConditionEvaluationResult.disabled("Skipping test because this run is configured to skip tests that are highly affected by rate limiting") + } else { + return ConditionEvaluationResult.enabled("Running test highly affected by rate limiting") + } + } + } +} diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/Constants.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/Constants.kt index baf3dcae3d11..9ea53b02baab 100644 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/Constants.kt +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/Constants.kt @@ -4,3 +4,4 @@ const val LOG_TAG = "mullvad-e2e" const val PARTNER_AUTH = "partner_auth" const val VALID_TEST_ACCOUNT_NUMBER_ARGUMENT_KEY = "valid_test_account_number" const val INVALID_TEST_ACCOUNT_NUMBER_ARGUMENT_KEY = "invalid_test_account_number" +const val IGNORE_HIGHLY_RATE_LIMITED = "ignore_highly_rate_limited_tests"