Skip to content

It'd be nice if we had a test helper for systematically injecting cancellations #77

Open
@njsmith

Description

@njsmith

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions