Skip to content

Fix flaky test in OfflineCustomerInfoCalculatorTest#997

Merged
vegaro merged 1 commit into
mainfrom
flaky-test
May 5, 2023
Merged

Fix flaky test in OfflineCustomerInfoCalculatorTest#997
vegaro merged 1 commit into
mainfrom
flaky-test

Conversation

@vegaro

@vegaro vegaro commented May 4, 2023

Copy link
Copy Markdown
Member

Brought up in #994 (comment)

There were two issues, one that requestDate was being mocked to the wrong value (a date in the past instead of now), and also that we were checking if an entitlement should be active, when it shouldn't be

@vegaro vegaro added the pr:fix A bug fix label May 4, 2023
@vegaro vegaro changed the title Try to fix flaky test Fix flaky test in OfflineCustomerInfoCalculatorTest May 4, 2023
testDateProvider = object : DateProvider {
override val now: Date
get() = dateInThePast
get() = requestDate

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was wrong, we were mocking the request date to a date in the past instead of in the present, making the request date very close to the expires date of one of the products.


// Made a purchase for p1m and then a purchase for not_bw after that one expired
// You can't have an active purchase of the same product different base plans at the same time
val oneHourAgo = 1.hours.ago()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We were making the same computation here as for request date making the expiration date to be sometimes after the request date (making the entitlement active), that's why the test was passing most of the times when we were checking for isActive = true. Although we actually wanted to check if isActive = false since it's an expired entitlement.

purchaseTime = twoHoursAgo.time,
),
false,
isActive = false,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this isActive is for the product, meaning if it comes from the queryPurchases call or from queryPurchasesHistory. It doesn't mean the entitlement is active or not.

@vegaro vegaro May 4, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Which makes me think... should we be using this for computation of the isActive in the entitlement? 🤔

cc: @tonidero

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We should test what happens if the device's clock is changed, but I assume the expiration date sent by Google is going to be accurate (device independent). Then rolling back the device clock to before the expiration date will make the entitlement active, if I am not wrong. I think we need to use the fact that the purchase is being returned by queryPurchases or not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah wait, ignore my previous comment, you're right if the user moves the device clock, it can indeed change to be active... So yeah, we need to make sure the expiration date we give accounts for moving the device clock. Great find!

expirationDate = oneHourAgo,
purchaseDate = twoHoursAgo,
originalPurchaseDate = notBwProductPurchaseDate,
isActive = false)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was wrong, we were checking if the entitlement was still active

@vegaro vegaro marked this pull request as ready for review May 4, 2023 23:40

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes sense and good catch!

@vegaro vegaro merged commit dd5c4b9 into main May 5, 2023
@vegaro vegaro deleted the flaky-test branch May 5, 2023 23:42
tonidero added a commit that referenced this pull request May 18, 2023
**This is an automatic release.**

### New Features
* CAT-859 Expose whether or not a SubscriptionOption is Prepaid in the
SDK (#1005) via Deema AlShamaa (@dalshamaa)
### Bugfixes
* [CF-1324] Fix personalizedPrice defaulting to false (#952) via beylmk
(@beylmk)
### Performance Improvements
* Store and return ETag last refresh time header (#978) via Toni Rico
(@tonidero)
### Dependency Updates
* Bump fastlane-plugin-revenuecat_internal from `3b03efa` to `fe45299`
(#991) via dependabot[bot] (@dependabot[bot])
* Bump danger from 9.2.0 to 9.3.0 (#981) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-revenuecat_internal from `8482a43` to `3b03efa`
(#974) via dependabot[bot] (@dependabot[bot])
* Bump fastlane from 2.212.1 to 2.212.2 (#973) via dependabot[bot]
(@dependabot[bot])
* Bump fastlane-plugin-revenuecat_internal from `9255366` to `8482a43`
(#961) via dependabot[bot] (@dependabot[bot])
### Other Changes
* Add proration modes to post to backend (#977) via swehner (@swehner)
* Added ENTITLEMENTS_COMPUTED_ON_DEVICE (#939) via Cesar de la Vega
(@vegaro)
* Fix flaky test in OfflineCustomerInfoCalculatorTest (#997) via Cesar
de la Vega (@vegaro)
* Fix `OfflineCustomerInfoCalculatorTest` `Unresolved reference:
ProducType` (#995) via Cesar de la Vega (@vegaro)
* Add support for product_plan_identifier for offline customer info
(#959) via Cesar de la Vega (@vegaro)
* Add non-subscriptions support to offline customer info (#958) via
Cesar de la Vega (@vegaro)
* Query only active purchases when generating offline entitlements
customer info (#1003) via Toni Rico (@tonidero)
* Fix `PurchasesIntegrationTest` building issue (#996 into main) (#998)
via Cesar de la Vega (@vegaro)
* Fail offline entitlements computation if product entitlement mapping
not available (#999) via Toni Rico (@tonidero)
* Fix  build_magic_weather lane (#993) via Cesar de la Vega (@vegaro)
* Add backend integration tests and test product entitlement mapping
endpoint (#988) via Toni Rico (@tonidero)
* Fix purchases integration tests (#980) via Toni Rico (@tonidero)
* Disable offline entitlements if active inapp purchases exist (#983)
via Toni Rico (@tonidero)
* Clear cached customer info upon entering offline entitlements mode
(#989) via Toni Rico (@tonidero)
* Update product entitlement mapping request to new format (#976) via
Toni Rico (@tonidero)
* Support enabling/disabling offline entitlements (#964) via Toni Rico
(@tonidero)
* Add back integration tests automation (#972) via Toni Rico (@tonidero)
* Upgrade to AGP 8.0 (#975) via Toni Rico (@tonidero)
* Extract post receipt logic to PostReceiptHelper (#967) via Toni Rico
(@tonidero)
* Add isServerDown to error callback for postReceipt and getCustomerInfo
requests (#963) via Toni Rico (@tonidero)
* Add back integration test flavors (#962) via Toni Rico (@tonidero)
* Fix storing test results (#966) via Cesar de la Vega (@vegaro)
* Extract detekt job from test job (#965) via Cesar de la Vega (@vegaro)


[CF-1324]:
https://revenuecats.atlassian.net/browse/CF-1324?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants