Tolerate both CancellationError and URLError in CancellationTests #45
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.
Motivation
When cancelling a Swift concurrency task during a streaming request then the error returned might be
URLError
with.cancelled
code orCancellationError
. 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 aCancellationError
was thrown instead of aURLError
.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
orCancellationError
, 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.