-
Notifications
You must be signed in to change notification settings - Fork 150
Task cancellation within a test is handled inconsistently #1289
Copy link
Copy link
Labels
bug🪲 Something isn't working🪲 Something isn't workingconcurrency🔀 Swift concurrency/sendability issues🔀 Swift concurrency/sendability issuesissue-handlingRelated to Issue handling within the testing libraryRelated to Issue handling within the testing libraryparameterized-testingRelated to parameterized testing functionalityRelated to parameterized testing functionalitytraitsIssues and PRs related to the trait subsystem or built-in traitsIssues and PRs related to the trait subsystem or built-in traitstriagedThis issue has undergone initial triageThis issue has undergone initial triage
Milestone
Metadata
Metadata
Assignees
Labels
bug🪲 Something isn't working🪲 Something isn't workingconcurrency🔀 Swift concurrency/sendability issues🔀 Swift concurrency/sendability issuesissue-handlingRelated to Issue handling within the testing libraryRelated to Issue handling within the testing libraryparameterized-testingRelated to parameterized testing functionalityRelated to parameterized testing functionalitytraitsIssues and PRs related to the trait subsystem or built-in traitsIssues and PRs related to the trait subsystem or built-in traitstriagedThis issue has undergone initial triageThis issue has undergone initial triage
Type
Fields
Give feedbackNo fields configured for Bug.
Today, the task cancellation APIs behave inconsistently in Swift Testing:
UnsafeCurrentTask.cancel()within a test body cancels the current test case but has no other observable effectsUnsafeCurrentTask.cancel()during trait evaluation will cancel the entire test run (!)try Task.checkCancellation()after task cancellation will record an error even though the test's task has been cancelledTask.cancel()andUnsafeCurrentTask.cancel()don't throw, so they don't implicitly provide for early termination, but they can be paired withthrow CancellationError()or even justreturn.The only reasonable behaviour for task cancellation in a test target is that, if you cancel the task associated with a test, it cancels the test.