Avoid reassigning task-local runtime state in a Runner's event handler unless it's nested #339
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.
This is a mitigation for a bug in which an expectation inside a
withTaskGroup
closure can cause a crash if it fails.Motivation:
It can sometimes be useful to perform expectations (e.g.
#expect
) within the body of the closure passed towithTaskGroup
or similar APIs. However, doing so currently causes a crash if the expectation fails, illustrated by this small example:Modifications:
This change avoids wrapping the event handler of a runner's configuration with one that reassigns a TaskLocal (potentially triggering the crash) unless that runner is running during the run operation of another runner. In other words, only mutate the TaskLocal for nested runners. Nesting, or running one runner in the context of another, is something which is only done in practice when performing tests of the testing library itself. Ordinary usage of the testing library only has one “outer“ runner.
Result:
The above example code no longer crashes, verified by the new unit test.
Checklist:
Resolves rdar://126132392