Repository navigation
Add throwing timeout variants of AtomTestContext wait functions - #212
Merged
Merged
Conversation
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>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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:)andwait(for:within:until:)throwing overloads that throwAtomTestContextTimeoutErroron timeout. - Adds a new public
AtomTestContextTimeoutErrortype 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
within:-labeled throwing overloads toAtomTestContextthat surface a timeout as a thrown error, instead of the silently ignorableBoolreturned by the existing functions.Motivation
The existing
wait/waitForUpdatereturnfalseon 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
wait/waitForUpdate) and distinguishes the throwing variants by a sharedwithin:label (requiredDouble). This reads as a variant of the existingwaitfamily and avoids any clash with Swift Testing's#expect/#requiremacros. The label difference (timeout:optional +Boolvswithin:required +throws) mirrors the behavioral difference (best-effort vs enforced).AtomTestContextTimeoutError: Error, CustomStringConvertiblecarrying thetimeoutduration for diagnostics.CancellationError, never as a timeout. The timeout error is only thrown afterTask.sleepcompletes normally, so on cancellationTask.sleepthrowsCancellationErrorbefore the timeout error is reached.wait(for:within:until:)returns immediately without throwing when the atom already satisfies the predicate.Verification
timeoutproperty).🤖 Generated with Claude Code