Fix flaky testCardArtImage_returnsNilWhenImageNotCached test 🪿✨ - #6872
Open
joyceqin-stripe wants to merge 1 commit into
Open
Fix flaky testCardArtImage_returnsNilWhenImageNotCached test 🪿✨#6872joyceqin-stripe wants to merge 1 commit into
joyceqin-stripe wants to merge 1 commit into
Conversation
When DownloadManager is initialized with isTesting: false (the default), it overrides the provided URLSessionConfiguration's urlCache with a disk-backed URLCache at a fixed path. This caused test ordering flakiness: testCardArtImage_returnsImageWhenCached seeds the disk cache, and a subsequent testCardArtImage_returnsNilWhenImageNotCached may read that stale disk data before removeAllCachedResponses() fully completes. Pass isTesting: true so the DownloadManager uses the explicit memory-only URLCache (diskCapacity: 0) the test sets up, eliminating the disk I/O race condition. Committed-By-Agent: goose
joyceqin-stripe
marked this pull request as ready for review
August 7, 2026 19:57
joyceqin-stripe
enabled auto-merge (squash)
August 7, 2026 20:18
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.
Minion run
Summary
Pass
isTesting: truewhen constructingDownloadManagerinSTPPaymentMethodCardArtImageTest.setUp()so the manager uses the test's explicit memory-onlyURLCacheinstead of a disk-backed one.Motivation
testCardArtImage_returnsNilWhenImageNotCachedwas flaky becauseDownloadManager.init(withisTesting: false, the default) unconditionally replaces the providedURLSessionConfiguration'surlCachewith a disk-backedURLCacheat a fixedSTPCachepath — discarding the memory-only cache the test configured. WhentestCardArtImage_returnsImageWhenCachedran first, it seeded image data to that shared disk cache. A subsequent run oftestCardArtImage_returnsNilWhenImageNotCachedwould create a newURLCachepointing to the same path, andURLCache.removeAllCachedResponses()(called inresetCache()) does not guarantee synchronous disk removal, sopromoteFromDiskCachecould still find and return the stale image — causing theXCTAssertNilto fail.Passing
isTesting: trueskips the disk cache setup entirely. TheDownloadManagerthen uses theURLCache(memoryCapacity: 5_000_000, diskCapacity: 0)already set on the config, eliminating the disk I/O race.Testing
Existing tests in
STPPaymentMethodCardArtImageTestcover the fix —testCardArtImage_returnsNilWhenImageNotCached(previously flaky) andtestCardArtImage_returnsImageWhenCached(verifies the positive case still works with the memory cache seeded viaseedURLCache).No tests were newly ignored.
Changelog
No user-facing change.