Skip to content

Follow-ups from PR #82 review: context error strings, child deadline intersection, deterministic timer tests #83

Description

@staheri14

Deferred, non-blocking items from the review of #82 (IrrevocableContext deadline/timeout support). Points 1, 4, 6, 7 were addressed in that PR; the following were intentionally left as follow-ups.

2. Centralize the deadline/cancelled error strings (DRY)

run() and err() each construct "context deadline exceeded" / "context cancelled" ad hoc, and the tests assert on .contains("deadline exceeded") / .contains("context cancelled"). The strings currently match, but nothing prevents drift.

  • Suggestion: small private helpers (e.g. deadline_err() / cancelled_err()) so the messages have a single source of truth.
  • Priority: low (pure maintainability).

3. Allow a child to have a shorter deadline than its parent

child() inherits the parent's deadline verbatim; there is no way to give a child a tighter deadline. Go's context.WithTimeout on a child intersects deadlines (child gets min(parent, new)).

  • Suggestion: a with_timeout-style constructor on an existing context that sets deadline = min(self.deadline, now + timeout); or at minimum document the current "inherit-only" behavior so callers don't assume Go-style intersection.
  • Priority: low/medium (semantic gap vs. the Go model this is loosely based on); out of scope for feat: adds deadline/timeout support to IrrevocableContext #82.

5. Make the timer-based tests deterministic

test_run_respects_deadline, test_is_deadline_exceeded, and test_run_cancellation_beats_deadline rely on wall-clock timing (real sleeps with generous margins). These can flake under CI load.

  • Suggestion: convert to #[tokio::test(start_paused = true)] + tokio::time::advance(..) for deterministic virtual time.
  • Priority: low (margins are generous today), but paused-time is the robust pattern.

Source: static review by Claude (@claude) on #82. Points renumbered per that review.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions