Skip to content

Keep storage tests off the real network - #454

Merged
didiergarcia merged 2 commits into
mainfrom
fix/deflake-network-tests
Oct 20, 2026
Merged

didiergarcia merged 2 commits into
mainfrom
fix/deflake-network-tests

Conversation

@didiergarcia

@didiergarcia didiergarcia commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the remaining flaky timeouts in StorageTests.testMemoryStorageRolloff and StressTests on Swift CI.

  • testMemoryStorageRolloff set no httpSession, so it hit the real network. A slow request keeps the Analytics instance alive past waitUntilFinished's 30s window. It now uses RestrictedHTTPSession.
  • The stress tests faked the network with a URLProtocol, but URLSession's 30s resource timeout still applies to those requests. On a busy runner some uploads went unanswered that long and failed with -1001, which the error handler reports as a storage failure. They now use a new InstantHTTPSession that answers with a 200 without going through URLSession, so there are no timers to expire. testMemoryStorageStress also used the real network and gets the same session.
  • The stress tests' error handlers are unchanged: any error still fails the test.

InstantHTTPSession follows URLSessionTask's lifecycle (nothing happens until resume(), .running until the completion runs) so SegmentDestination's pending-upload tracking behaves as it does with a real session. File uploads still read the batch file.

Verified:

  • rolloff with 35s-slow requests fails with the same TimedOutError as CI. It passes with the change.
  • stress test with the first upload stalled 35s: fails like CI with the old session, passes cleanly with the new one.
  • stress test with one failed upload still fails with "Storage Error".
  • Full suites pass locally on macOS (227), iOS (243), tvOS (239) and watchOS (222).

testMemoryStorageRolloff and testMemoryStorageStress used the real network;
a slow request kept Analytics alive past waitUntilFinished's timeout. Give
them RestrictedHTTPSession.

On a busy runner the stress tests' faked uploads can still hit URLSession's
timeout. The batch stays in storage and is resent, so don't fail the test
on that error.
URLSession's resource timeout still applies to URLProtocol-faked requests,
so a busy runner could fail uploads with -1001. InstantHTTPSession answers
without URLSession, so the stress tests keep their strict error handlers.
@didiergarcia
didiergarcia merged commit 2948a17 into main Oct 20, 2026
19 of 20 checks passed
@didiergarcia
didiergarcia deleted the fix/deflake-network-tests branch October 20, 2026 22:14
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