Open
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