Skip to content

Commit

Permalink
Introduce HighlyRateLimited tag for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund committed Aug 15, 2024
1 parent a543647 commit 422c06e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions android/test/e2e/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ android {
put("clearPackageData", "true")
addOptionalPropertyAsArgument("valid_test_account_number")
addOptionalPropertyAsArgument("invalid_test_account_number")
addOptionalPropertyAsArgument("ignore_highly_rate_limited_tests")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 422c06e

Please sign in to comment.