Skip to content

Add throwing timeout variants of AtomTestContext wait functions - #212

Merged
ra1028 merged 2 commits into
mainfrom
add-throwing-wait-timeout
Jun 17, 2026
Merged

ra1028 merged 2 commits into
mainfrom
add-throwing-wait-timeout

Conversation

@ra1028

@ra1028 ra1028 commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

Add within:-labeled throwing overloads to AtomTestContext that surface a timeout as a thrown error, instead of the silently ignorable Bool returned by the existing functions.

// New (throwing) — timeout surfaces as an error
try await context.waitForUpdate(within: 1)
try await context.wait(for: atom, within: 1, until: \.isSuccess)

// Existing (best-effort, returns whether it happened) — unchanged
let didUpdate = await context.waitForUpdate(timeout: 1)
let didUpdate = await context.wait(for: atom, timeout: 1, until: \.isSuccess)

Motivation

The existing wait/waitForUpdate return false on timeout, so a timeout is silently ignored unless the caller inspects the return value. The throwing variants make a timeout fail the test by default.

Design notes

  • Naming: keeps the same base names (wait / waitForUpdate) and distinguishes the throwing variants by a shared within: label (required Double). This reads as a variant of the existing wait family and avoids any clash with Swift Testing's #expect / #require macros. The label difference (timeout: optional + Bool vs within: required + throws) mirrors the behavioral difference (best-effort vs enforced).
  • Error type: a new public AtomTestContextTimeoutError: Error, CustomStringConvertible carrying the timeout duration for diagnostics.
  • Cancellation: a real task cancellation propagates as CancellationError, never as a timeout. The timeout error is only thrown after Task.sleep completes normally, so on cancellation Task.sleep throws CancellationError before the timeout error is reached.
  • Already-satisfied: wait(for:within:until:) returns immediately without throwing when the atom already satisfies the predicate.

Verification

  • New tests cover the success path, the already-satisfied path, and the timeout-throws path (asserting the timeout property).
  • Full library suite passes and was run 10 times under parallel execution with no failures.

🤖 Generated with Claude Code

Add `within:`-labeled throwing overloads to AtomTestContext that surface a
timeout as a thrown error instead of a silently ignorable boolean:

- `waitForUpdate(within:) async throws`
- `wait(for:within:until:) async throws`

A timeout throws the new public `AtomTestContextTimeoutError`, which carries
the `timeout` duration for diagnostics. Real task cancellation continues to
propagate as `CancellationError` and is never reported as a timeout, because
the timeout error is only thrown after `Task.sleep` completes normally.

The existing non-throwing, boolean-returning `wait`/`waitForUpdate` overloads
are kept unchanged. The throwing predicate variant returns immediately when
the atom already satisfies the predicate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 17, 2026 06:07
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds throwing within: overloads to AtomTestContext wait APIs so that timeouts fail tests by default (via a thrown error) rather than being silently ignorable through a Bool return value.

Changes:

  • Introduces waitForUpdate(within:) and wait(for:within:until:) throwing overloads that throw AtomTestContextTimeoutError on timeout.
  • Adds a new public AtomTestContextTimeoutError type to carry the timeout duration for diagnostics.
  • Adds tests for success, already-satisfied, and timeout-throws paths; updates DocC symbol listing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Tests/AtomsTests/Context/AtomTestContextTests.swift Adds coverage for the new throwing timeout variants (success, immediate satisfaction, and timeout error).
Sources/Atoms/Context/AtomTestContext.swift Implements throwing within: overloads using an update stream race vs. timeout sleep.
Sources/Atoms/AtomTestContextTimeoutError.swift Defines the new public timeout error type with a timeout payload and description.
Sources/Atoms/Atoms.docc/Atoms.md Exposes the new error type in the DocC topics list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ra1028
ra1028 merged commit 18bb309 into main Jun 17, 2026
4 checks passed
@ra1028
ra1028 deleted the add-throwing-wait-timeout branch June 17, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants