Skip to content

Commit 309a35a

Browse files
authored
[in_app_purchase_storekit] Address flaky tests (#11270)
Fixes flutter/flutter#182845 Probably fixes flutter/flutter#183318 ## Pre-Review Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran [the auto-formatter]. - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1]. - [x] I updated/added any relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord].
1 parent 52eb336 commit 309a35a

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchaseStoreKit2PluginTests.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ final class InAppPurchase2PluginTests: XCTestCase {
181181
//TODO(louisehsu): Add testing for lower versions.
182182
@available(iOS 17.0, macOS 14.0, *)
183183
func testGetProductsWithStoreKitError() async throws {
184+
let osVersion = ProcessInfo.processInfo.operatingSystemVersion
185+
try XCTSkipIf(
186+
// https://developer.apple.com/forums/thread/808030
187+
osVersion.majorVersion == 26 && osVersion.minorVersion == 2,
188+
"Known StoreKitTest bug on Xcode 26.2 with setSimulatedError() when used on .loadProducts API"
189+
)
190+
184191
try await session.setSimulatedError(
185192
.generic(.networkError(URLError(.badURL))), forAPI: .loadProducts)
186193

@@ -217,6 +224,15 @@ final class InAppPurchase2PluginTests: XCTestCase {
217224

218225
@available(iOS 17.0, macOS 14.0, *)
219226
func testFailedNetworkErrorPurchase() async throws {
227+
let osVersion = ProcessInfo.processInfo.operatingSystemVersion
228+
try XCTSkipIf(
229+
// https://developer.apple.com/forums/thread/808030
230+
osVersion.majorVersion == 26 && osVersion.minorVersion == 2,
231+
"Known StoreKitTest bug on Xcode 26.2 with setSimulatedError() when used on .loadProducts API"
232+
)
233+
234+
// StoreKitTest aggressively caches products and transaction, which means sometimes it bypasses a simulated error.
235+
session.clearTransactions()
220236
try await session.setSimulatedError(
221237
.generic(.networkError(URLError(.badURL))), forAPI: .loadProducts)
222238
let expectation = self.expectation(description: "products request should fail")
@@ -290,7 +306,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
290306
XCTFail("Purchase should NOT fail. Failed with \(error)")
291307
}
292308
}
293-
await fulfillment(of: [expectation], timeout: 5)
309+
await fulfillment(of: [expectation], timeout: 10)
294310
}
295311

296312
func testDiscountedProductSuccess() async throws {
@@ -303,7 +319,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
303319
XCTFail("Purchase should NOT fail. Failed with \(error)")
304320
}
305321
}
306-
await fulfillment(of: [expectation], timeout: 5)
322+
await fulfillment(of: [expectation], timeout: 10)
307323
}
308324

309325
func testPurchaseWithAppAccountToken() async throws {

0 commit comments

Comments
 (0)