BasePurchasesTests: added assertion to ensure Purchases does not leak#2104
Merged
Conversation
vegaro
approved these changes
Dec 7, 2022
|
|
||
| self.deviceCache = nil | ||
| self.purchases = nil | ||
| } |
…leak To continue debugging [CSDK-517], this adds an assertion to make sure that we don't leak `Purchases`, either because of a retain cycle, or due to any `XCTest` issue.
ec006ee to
425de93
Compare
NachoSoto
added a commit
that referenced
this pull request
May 23, 2023
While working on #2533, I knew that my proof of concept had a retain cycle. I however was very confused when it wasn't detected by this mechanism introduced first introduced in #2104. Turns out that this had been wrong the whole time: the current implementation, as explained by the comment, was executing those blocks in LIFO order, which meant that the references were being set to `nil` before the assertions could be created. This meant that by the time the `except { [weak purchases = self.purchases] ... }` lines were called, `self.purchases` itself was `nil`, so nothing was being checked. This simplifies the implementation by inlining the checks, and saving a `weak` reference before clearing the singleton and all the local references. Luckily there was only one failing test that had to do with how `Purchases` was being created, and implementation details of `expectFatalError`. To avoid this, I changed the test to use the `Purchases.init` method directly.
NachoSoto
added a commit
that referenced
this pull request
May 24, 2023
While working on #2533, I knew that my proof of concept had a retain cycle. I however was very confused when it wasn't detected by this mechanism introduced first introduced in #2104. Turns out that this had been wrong the whole time: the current implementation, as explained by the comment, was executing those blocks in LIFO order, which meant that the references were being set to `nil` before the assertions could be created. This meant that by the time the `except { [weak purchases = self.purchases] ... }` lines were called, `self.purchases` itself was `nil`, so nothing was being checked. This simplifies the implementation by inlining the checks, and saving a `weak` reference before clearing the singleton and all the local references. Luckily there was only one failing test that had to do with how `Purchases` was being created, and implementation details of `expectFatalError`. To avoid this, I changed the test to use the `Purchases.init` method directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To continue debugging CSDK-517, this adds an assertion to make sure that we don't leak
Purchases, either because of a retain cycle, or due to anyXCTestissue.