apple / swift-openapi-urlsession

URLSession transport for Swift OpenAPI Generator.
https://swiftpackageindex.com/apple/swift-openapi-urlsession/documentation
Apache License 2.0
160 stars 29 forks source link

Tolerate both CancellationError and URLError in CancellationTests #45

Closed simonjbeaumont closed 8 months ago

simonjbeaumont commented 8 months ago

Motivation

When cancelling a Swift concurrency task during a streaming request then the error returned might be URLError with .cancelled code or CancellationError. The tests tried to be smart and expect just one of these depending on which stage of the request we were at, but there are still some races, and this test fails very rarely because a CancellationError was thrown instead of a URLError.

Modifications

This patch updates the test to tolerate both kinds of error at this stage of the request.

Result

The test will pass if the error is either URLError with .cancelled or CancellationError, and continue to fail if there is any other kind of error or no error.

Test Plan

Existing tests, which failed when run repeatedly for 1k runs, now pass when run for 10k runs.