Repository navigation
Retry testGetTasks and testGetAllTasks when the request finishes first - #138
Merged
Merged
Conversation
Both tests resume a real request and then expect the session to list it. If the request completes before the listing, the session no longer lists it and the assertions fail. Their retry loops catch thrown assertion errors, which only happens on the Kotlin side; XCTest on Darwin records failures without throwing, so they never retried there. Detect that case (no tasks listed and the task completed) and retry with a new request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marcprux
approved these changes
Oct 20, 2026
marcprux
left a comment
Member
There was a problem hiding this comment.
Nice improvement. In an ideal world, this (and other) network tests would be hitting some localhost mini server that we spin up for testing, since testing against the real network is an endless source of flakiness. But for the time being, we can at least reduce the failure rate with this.
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.
What
testGetTasksandtestGetAllTasksinTestURLSessionfailed now and then on CI with:Both tests resume a real request against
testURLand then expectsession.tasks(orallTasks) to list it. If the request completes first, the session no longer lists it and the assertions fail.The tests already retry up to five times, but only by catching thrown assertion errors. On the Kotlin side that's
java.lang.AssertionError. On Darwin,XCTAssert…records the failure without throwing, so the retry never happened there.Each test now checks for that case before asserting: if nothing is listed and the task is already
.completed, it tries again with a new request. The last attempt still asserts, so a real regression still fails.Testing
resume()on the first attempt only, so the request completes before the listing.("0") is not equal to ("1")/XCTAssertTrue failedas CI..completed, the same as on Darwin.swift test --filter 'TestURLSession/testGet'passed 10 out of 10 runs on macOS.TestURLSessionon Robolectric: 12 tests, 2 skipped as before, 0 failures.session.tasks, unlike SkipFoundation, which lists it from creation. So listing beforeresume()wouldn't be a portable fix.Skip Pull Request Checklist:
swift test🤖 Generated with Claude Code