Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.test.espresso.web.webdriver.Locator
import androidx.test.ext.junit.rules.activityScenarioRule
import com.stripe.android.connect.webview.serialization.AlertJs
import com.stripe.android.connect.webview.serialization.ConnectJson
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.equalTo
import org.junit.After
Expand All @@ -52,7 +52,7 @@ class FullScreenComponentTest {
@get:Rule
val ruleChain: RuleChain = RuleChain
.outerRule(activityRule)
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))

private val rootView
get() = isAssignableFrom(StripeComponentDialogFragmentView::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.core.utils.FeatureFlags
import com.stripe.android.crypto.onramp.example.store.ONRAMP_PREFS_NAME
import com.stripe.android.testing.FeatureFlagTestRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -44,7 +44,7 @@ class OnrampFlowTest {
val rule = RuleChain.emptyRuleChain()
.around(composeRule)
.around(attestationFeatureFlagTestRule)
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))
.around(activityRule)

private val defaultTimeout: Duration = 30.seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.test.espresso.web.webdriver.Locator
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.stripe.android.paymentmethodmessaging.element.PaymentMethodMessagingElement.Appearance.Theme
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import org.hamcrest.Matchers.containsString
import org.junit.Rule
import org.junit.Test
Expand All @@ -26,7 +26,7 @@ internal class LearnMoreActivityTest {
private val applicationContext = ApplicationProvider.getApplicationContext<Application>()

@get:Rule
val retryRule = RetryRule(3)
val shampooRule = ShampooRule(iterations = 5)

@Test
fun loadsUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.stripe.android.networktesting.RequestMatchers.method
import com.stripe.android.networktesting.RequestMatchers.path
import com.stripe.android.networktesting.ResponseReplacement
import com.stripe.android.networktesting.testBodyFromFile
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -29,7 +29,7 @@ class PaymentMethodMessagingElementTest {
val testRule: RuleChain = RuleChain.emptyRuleChain()
.around(composeTestRule)
.around(networkRule)
.around(RetryRule(5))
.around(ShampooRule(iterations = 5))
.around(AdvancedFraudSignalsTestRule())

private val getConfigRequestMatcher = composite(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
package com.stripe.android.testing

import android.util.Log
import leakcanary.NoLeakAssertionFailedError
import org.junit.AssumptionViolatedException
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

class RetryRule(private val attempts: Int) : TestRule {
class RetryRule() : TestRule {
override fun apply(base: Statement, description: Description): Statement {
val logTag = description.className
return object : Statement() {
@Throws
override fun evaluate() {
if (BuildConfig.IS_RUNNING_IN_CI) {
for (attempt in 1..attempts) {
val isLast = attempts == attempt
runCatching {
base.evaluate()
}.onSuccess {
return
}.onFailure { error ->
if (isLast || error is AssumptionViolatedException || error is NoLeakAssertionFailedError) {
throw error
}
Log.d(logTag, "Failed attempt $attempt out of $attempts with error")
}
}
} else {
base.evaluate()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.stripe.android.networking.StripeRepository
import com.stripe.android.testing.AbsFakeStripeRepository
import com.stripe.android.testing.AbsPaymentController
import com.stripe.android.testing.CoroutineTestRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
Expand Down Expand Up @@ -56,7 +56,7 @@ class RadarSessionTest {
val ruleChain: RuleChain = RuleChain
.outerRule(CoroutineTestRule(testDispatcher))
.around(scenarioRule)
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))

@Test
fun ensureRadarSessionsAttachHCaptchaToken(): Unit = runTest(testDispatcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import com.stripe.android.PaymentConfiguration
import com.stripe.android.R
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -34,7 +34,7 @@ class CardInputWidgetTest {
@get:Rule
val rule = RuleChain.emptyRuleChain()
.around(composeTestRule)
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))
.around(activityRule)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ internal class PlaygroundTestDriver(

private fun monitorCurrentActivity(application: Application) {
this.application = application
// Unregister first so retried attempts (e.g. RetryRule) don't stack callbacks.
// Unregister first so repeated attempts (e.g. ShampooRule) don't stack callbacks.
application.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks)
application.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.ui.test.junit4.createEmptyComposeRule
import com.stripe.android.paymentsheet.example.BuildConfig
import com.stripe.android.test.core.INDIVIDUAL_TEST_TIMEOUT_SECONDS
import com.stripe.android.testing.QuarantinedTestRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
Expand Down Expand Up @@ -48,7 +48,7 @@ class TestRules private constructor(
}
}.let { chain ->
if (BuildConfig.IS_RUNNING_IN_CI && !BuildConfig.RUN_LATENCY_TESTS_IN_CI) {
chain.around(RetryRule(retryCount))
chain.around(ShampooRule(iterations = 5))
} else {
chain
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.stripe.android.paymentsheet.utils
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import com.stripe.android.networktesting.NetworkRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
Expand Down Expand Up @@ -35,7 +35,7 @@ class TestRules private constructor(
.around(DetectLeaksAfterTestSuccess())
.around(FakeGooglePayRepositoryRule())
.around(composeTestRule)
.around(RetryRule(5))
.around(ShampooRule(iterations = 5))
.around(networkRule)
.around(terminalTestRule)
.block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.stripe.android.paymentsheet.state.LinkSignupModeResult
import com.stripe.android.paymentsheet.state.LinkState
import com.stripe.android.testing.FeatureFlagTestRule
import com.stripe.android.testing.PaymentConfigurationTestRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import com.stripe.android.testing.createComposeCleanupRule
import com.stripe.android.tta.testing.TapToAddCardAddedPage
import com.stripe.android.tta.testing.TapToAddCardCollectionTestHelper
Expand Down Expand Up @@ -76,7 +76,7 @@ class TapToAddActivityTest {
.around(imageLoaderTestRule)
.around(FeatureFlagTestRule(FeatureFlags.forceTapToAddWithTerminal, isEnabled = true))
.around(PaymentConfigurationTestRule(applicationContext))
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))
.around(intentsRule)

private val linkHelper = TapToAddLinkTestHelper(composeTestRule, networkRule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.stripe.android.paymentelement.confirmation.lpms.foundations.network.M
import com.stripe.android.paymentelement.confirmation.lpms.foundations.network.PublishableKeyFetcher
import com.stripe.android.paymentsheet.addresselement.AddressDetails
import com.stripe.android.paymentsheet.createTestActivityRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import com.stripe.android.utils.PaymentElementCallbackTestRule
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
Expand All @@ -40,7 +40,7 @@ internal open class BaseLpmNetworkTest(
.around(createTestActivityRule<LpmNetworkTestActivity>())
.around(IntentsRule())
.around(PaymentElementCallbackTestRule())
.around(RetryRule(attempts = 3))
.around(ShampooRule(iterations = 5))

fun test(
testType: TestType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.stripe.android.paymentsheet.R
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.ui.SHEET_NAVIGATION_BUTTON_TAG
import com.stripe.android.testing.PaymentConfigurationTestRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import com.stripe.android.ui.core.cbc.CardBrandChoiceEligibility
import com.stripe.paymentelementnetwork.CardPaymentMethodDetails
import com.stripe.paymentelementnetwork.setupPaymentMethodDetachResponse
Expand Down Expand Up @@ -67,7 +67,7 @@ internal class EmbeddedSheetActivityTest {
.outerRule(composeTestRule)
.around(networkRule)
.around(PaymentConfigurationTestRule(applicationContext))
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))

@Test
fun `when launched without args should finish with error result`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import com.stripe.android.paymentsheet.ui.getLabel
import com.stripe.android.paymentsheet.utils.ViewModelStoreTestRule
import com.stripe.android.testing.CleanupTestRule
import com.stripe.android.testing.FakeErrorReporter
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import com.stripe.android.uicore.elements.bottomsheet.BottomSheetContentTestTag
import com.stripe.android.utils.FakeIsNfcScanningAvailable
import com.stripe.android.utils.FakeLinkConfigurationCoordinator
Expand Down Expand Up @@ -93,7 +93,7 @@ internal class PaymentOptionsActivityTest {
.around(coroutineScopeCleanupRule)
.around(composeTestRule)
.around(networkRule)
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))

@get:Rule
val viewModelStoreRule = ViewModelStoreTestRule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ import com.stripe.android.testing.DummyActivityResultCaller
import com.stripe.android.testing.FakeErrorReporter
import com.stripe.android.testing.PaymentIntentFactory
import com.stripe.android.testing.ResetMockRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import com.stripe.android.testing.SessionTestRule
import com.stripe.android.ui.core.Amount
import com.stripe.android.uicore.elements.IdentifierSpec
Expand Down Expand Up @@ -191,7 +191,7 @@ internal class PaymentSheetViewModelTest {
.around(SessionTestRule())
.around(PaymentElementCallbackTestRule())
.around(ResetMockRule(eventReporter))
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))

@BeforeTest
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.stripe.android.networktesting.elementsSession
import com.stripe.android.networktesting.testBodyFromFile
import com.stripe.android.paymentsheet.state.PaymentElementLoader
import com.stripe.android.testing.PaymentConfigurationTestRule
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import com.stripe.android.testing.createComposeCleanupRule
import com.stripe.paymentelementnetwork.CardPaymentMethodDetails
import com.stripe.paymentelementnetwork.UsBankPaymentMethodDetails
Expand Down Expand Up @@ -60,7 +60,7 @@ internal class VerticalModePaymentSheetActivityTest {
.around(composeTestRule)
.around(networkRule)
.around(PaymentConfigurationTestRule(applicationContext))
.around(RetryRule(3))
.around(ShampooRule(iterations = 5))

@Test
fun `Allows paying with card`() = runTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.stripe.android.camera.framework.image.size
import com.stripe.android.camera.framework.util.toRect
import com.stripe.android.stripecardscan.framework.ResourceFetcher
import com.stripe.android.stripecardscan.test.R
import com.stripe.android.testing.RetryRule
import com.stripe.android.testing.ShampooRule
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
Expand All @@ -25,7 +25,7 @@ class SSDOcrTest {
private val testContext = InstrumentationRegistry.getInstrumentation().context

@get:Rule
val retryRule = RetryRule(3)
val shampooRule = ShampooRule(iterations = 5)

@Before
fun initializeTfLite() {
Expand Down
Loading