Skip to content

Task cancellation within a test is handled inconsistentlyΒ #1289

@grynspan

Description

@grynspan

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 effects
  • UnsafeCurrentTask.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 cancelled

Task.cancel() and UnsafeCurrentTask.cancel() don't throw, so they don't implicitly provide for early termination, but they can be paired with throw CancellationError() or even just return.

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.

Metadata

Metadata

Assignees

Labels

bugπŸͺ² Something isn't workingconcurrencyπŸ”€ Swift concurrency/sendability issuesissue-handlingRelated to Issue handling within the testing libraryparameterized-testingRelated to parameterized testing functionalitytraitsIssues and PRs related to the trait subsystem or built-in traitstriagedThis issue has undergone initial triage

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions