Skip to content

Commit

Permalink
Integration Tests: fix potential crash on tearDown (#3401)
Browse files Browse the repository at this point in the history
I ran into this locally. We re-initialize `Purchases` on some tests to
simulate re-starting apps. If a test fails mid-test, `Purchases.shared`
might not be defined.
  • Loading branch information
NachoSoto authored Nov 10, 2023
1 parent 95641a5 commit 28fce4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,10 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void
}

static func clearSingleton() {
Self.purchases.value = nil
self.purchases.modify { purchases in
purchases?.delegate = nil
purchases = nil
}
}

/// - Parameter purchases: this is an `@autoclosure` to be able to clear the previous instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ private extension BaseBackendIntegrationTests {
// - These run *before* `tearDown`.
// - They run in LIFO order.
self.addTeardownBlock {
Purchases.shared.delegate = nil
Purchases.clearSingleton()

// Note: this captures the boolean to avoid race conditions when Nimble tries
Expand Down

0 comments on commit 28fce4b

Please sign in to comment.