python-trio / python-trio/trio
It'd be nice if we had a test helper for systematically injecting cancellations
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
It's well known that error handling and cleanup code is notoriously prone to bugs, because it's hard to test and often untested. We have full visibility into the cancellation states of the code we run; it should be possible to provide a pretty sweet fault injection framework to test cancellation handling.
For example, a possible API would be: run this test function repeatedly, while injecting cancellations at different points, until all possible cancellations have been tried, and let any exceptions escape
Technically, this might be implemented as:
- keep a record of places where we have issued a cancellation (keyed by stack snapshots or similar)
- when we do an "are we cancelled?" check, first check against this database, and if we're at a never-seen-before location then immediately issue a cancellation
There's some subtlety to the choice of key:
- we might want to distinguish between the different cancel scopes in the stack (e.g. the first time we hit cancel point X, cancel the topmost scope; the second time we hit cancel point X, cancel the next-to-topmost scope, etc., and only move on to the next cancel point after we've exercised all the scopes at the first cancel point)
- for the very common case of I/O loops, we might want to distinguish cancellation on the first-iteration versus later-iterations?
It would also be neat if there were a way to teach coverage to report on which cancellation branches had been exercised.
See also: #239
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by reviewing the cancellation checks described in the issue and the related discussion in #239; a complete result would define and implement the proposed systematic injection behavior, including cancel scopes and loop iterations, with coverage reporting if that remains in scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100