Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few flaky tests #3833

Merged
merged 22 commits into from
May 17, 2024
Merged

Fix a few flaky tests #3833

merged 22 commits into from
May 17, 2024

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Apr 22, 2024

Looking into our flaky tests, I noticed that calls to forceRenewalOfSubscription don't always trigger calls from StoreKit.product.updates, it's flaky as hell.

I tried instead using an accelerated timeRate value and adding explicit waits, and that seems to consistently work in local testing. Opening this up to see if this helps with the flakiness of these particular tests.

Notes from Josh

@aboedo aboedo added the test Adding missing tests or correcting existing tests label Apr 22, 2024
@aboedo aboedo self-assigned this Apr 22, 2024
@RevenueCat-Danger-Bot
Copy link

RevenueCat-Danger-Bot commented Apr 29, 2024

1 Message
📖 Size increase: 13.73 KB

Generated by 🚫 Danger

@joshdholtz joshdholtz changed the base branch from main to retry-tests May 16, 2024 17:16
@joshdholtz joshdholtz requested a review from a team May 17, 2024 13:23
@joshdholtz joshdholtz marked this pull request as ready for review May 17, 2024 13:23

try self.testSession.forceRenewalOfSubscription(productIdentifier: productIdentifier)
// swiftlint:disable:next force_try
try! await Task.sleep(nanoseconds: 3 * 1_000_000_000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never thought I'd say this, but sleeping in this test actually makes more sense than relying on the old flaky StoreKit behavior 😂

@@ -241,16 +243,23 @@ class OfflineStoreKit1IntegrationTests: BaseOfflineStoreKitIntegrationTests {

@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
func testCallToGetCustomerInfoWithPendingTransactionsPostsReceiptOnlyOnce() async throws {
// forceRenewalOfSubscription doesn't work well, so we use this instead
if #available(iOS 16.4, *) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we have this code duplicated in several tests, could it be abstracted out to a common function in BaseStoreKitIntegrationTests?

@@ -641,21 +683,21 @@ class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {
await waitForNewPurchaseDate()

// 4. Expire subscription
try await self.expireSubscription(entitlement)
// try await self.expireSubscription(entitlement)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is commenting out the latter part of this test intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! I noticed this a bit ago and am fixing 😛

if #available(iOS 16.4, *) {
self.testSession.timeRate = .oneRenewalEveryTwoSeconds
} else {
self.testSession.timeRate = SKTestSession.TimeRate.monthlyRenewalEveryThirtySeconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this fail if we use SKTestSession.TimeRate.monthlyRenewalEveryThirtySeconds on iOS <16.4 and then sleep for 3 seconds later in the test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fire-at-will We only run backend tests on iOS 17 right now so... odds are this will never happen 😛

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤪

@fire-at-will
Copy link
Contributor

@joshdholtz Looks good! I had a few suggestions/questions and then I think it'll be good to go!

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the existing comments but looking good!

try await self.purchaseShortestDuration(allowOfflineEntitlements: true)

// swiftlint:disable:next force_try
try! await Task.sleep(nanoseconds: 3 * 1_000_000_000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 3 * 1_000_000_000 seems to be used in a few tests. Could we extract it somewhere?

RETRY_SCAN_SAVE_FAILED_TESTS_CUSTOM_VALUE = :RETRY_SCAN_SAVE_FAILED_TESTS_CUSTOM_VALUE
end

class RetryScanSaveFailedTestsAction < Action
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we should move this to the plugin, so it can also be tested... But since I think it will only be used here for now, I think this is ok 👍

@joshdholtz joshdholtz merged commit 032bcb9 into retry-tests May 17, 2024
24 checks passed
@joshdholtz joshdholtz deleted the andy/fix_some_flaky_tests branch May 17, 2024 19:13
joshdholtz added a commit that referenced this pull request May 17, 2024
This is "ready for review" but it requires
#3833 to be merged into
it first to fully pass

### Motivation

Prevent the need to fully rerun all backend tests job when only a few
flaky tests fail

### Description

1. Runs backend integration tests
    - Parses junit.xml for failed tests
    - Writes them to a file
2. Runs new step in CircleCI
    - Looks at file for tests to re-run and only runs those tests
    - Merges new junit.xml into original junit.xml

The retry happens 4 times right now and will fail (raise an error) if
there are any left over tests that never ended up passing

---------

Co-authored-by: Will Taylor <wtaylor151@gmail.com>
Co-authored-by: Andy Boedo <andresboedo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Adding missing tests or correcting existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants