Skip to content

Extracted asyncWait to poll async conditions in tests#2134

Merged
NachoSoto merged 2 commits into
mainfrom
async-await
Dec 15, 2022
Merged

Extracted asyncWait to poll async conditions in tests#2134
NachoSoto merged 2 commits into
mainfrom
async-await

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

This is necessary because we can't use Quick v6.x yet.

Abstracting this out to use it in #2069.

This is necessary because we can't use `Quick` v6.x yet.

Abstracting this out to use it in #2069.

@vegaro vegaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@NachoSoto NachoSoto merged commit c8ed10d into main Dec 15, 2022
@NachoSoto NachoSoto deleted the async-await branch December 15, 2022 16:51
NachoSoto added a commit that referenced this pull request Dec 15, 2022
…ottle errors (#2146)

Fixes #2116.

Depends on #2134, #2144, #2145.

We've known that, especially for sandbox accounts with lots of
purchases, the SDK can get flooded with a lot of transactions to process
at once.
I've been making some improvements for this (like #2115).

Another consequence of this behavior, is that we can end up failing due
to `StoreKit` throttling us (see #2116):

> 2022-12-03 12:31:58.670892+0100 app[673:61074]
<SKReceiptRefreshRequest: 0x283edc860>: Finished refreshing receipt with
error: Error Domain=ASDErrorDomain Code=603 "Request throttled"
UserInfo={NSLocalizedFailureReason=Unified receipt is valid and current,
NSLocalizedDescription=Request throttled, AMSServerErrorCode=0}

This change avoids that by skipping the refresh if less than 2 seconds
have elapsed. I chose 2 to make this a low-ish risk change, with a huge
benefit for multiple semi-concurrent requests coming from a big
transaction queue.
NachoSoto added a commit that referenced this pull request Dec 15, 2022
)

See [TRIAGE-179].

I wrote all these to cover the change in #2063. I wrote a failing test
that only passed with the change in #2063. However, when running that in
SK1, that would fail.
With the change as suggested in #2063, the SK2 behavior would differ
from SK1.

From the `Transaction.all` docs:
> This sequence returns the user’s transaction history current to the
moment you access the sequence. The sequence emits a finite number of
transactions. If the App Store processes new transactions for the user
while you’re accessing this sequence, the new transactions appear in the
transaction listener, updates.

These new tests verify the behavior of the SDK when encountering
transactions created prior to initializing the SDK, and some made after
initialization.

Integration tests now are as follows:
- `BaseStoreKitIntegrationTests`
  - `StoreKit1IntegrationTests`
  - `StoreKit2IntegrationTests`
  - `BaseStoreKitObserverModeIntegrationTests`:
    - `StoreKit1ObserverModeIntegrationTests`
    - `StoreKit2ObserverModeIntegrationTests`
    - `StoreKit1ObserverModeWithExistingPurchasesTests`
    - `StoreKit2ObserverModeWithExistingPurchasesTests`

Depends on #2064, #2066, and #2134.

[TRIAGE-179]:
https://revenuecats.atlassian.net/browse/TRIAGE-179?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
NachoSoto pushed a commit that referenced this pull request Dec 15, 2022
**This is an automatic release.**

### Bugfixes
* Fix sending presentedOfferingIdentifier in StoreKit2 (#2156) via Toni
Rico (@tonidero)
* `ReceiptFetcher`: throttle receipt refreshing to avoid `StoreKit`
throttle errors (#2146) via NachoSoto (@NachoSoto)
### Other Changes
* Added integration and unit tests to verify observer mode behavior
(#2069) via NachoSoto (@NachoSoto)
* Created `ClockType` and `TestClock` to be able to mock time (#2145)
via NachoSoto (@NachoSoto)
* Extracted `asyncWait` to poll `async` conditions in tests (#2134) via
NachoSoto (@NachoSoto)
* `StoreKitRequestFetcher`: added log when starting/ending requests
(#2151) via NachoSoto (@NachoSoto)
* `CI`: fixed `PurchaseTester` deployment (#2147) via NachoSoto
(@NachoSoto)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants