Repository navigation
Conversation
mafredri
force-pushed
the
mafredri/context-trap-cause
branch
from
November 3, 2026 15:16
95929bd to
aa5e14d
Compare
Trap().WithTimeout() did not catch WithTimeoutCause() calls, and Trap().WithDeadline() did not catch WithDeadlineCause(), so a test had to know which variant the code under test calls to trap it. The cause variants now match their base function's trap, and Call.Cause still exposes the cause. This removes the separate WithDeadlineCause and WithTimeoutCause trappers, which are not on main or in any release.
TestWithTimeout_Trap duplicated the WithTimeout row of the cause variant test. TestTrap_Contexts now has one row per context function, and each row also checks that the released context expires on Advance, which only the WithTimeout case checked before. The negative control for a call without the trap's tags is gone. It tested generic tag filtering, which Test_MultipleTraps covers, and did not control for which function a trap catches.
A user reading the Contexts section had no way to learn that Trap().WithTimeout() and Trap().WithDeadline() also catch the cause variants, now that the separate cause trappers are gone.
mafredri
force-pushed
the
mafredri/context-trap-cause
branch
from
November 4, 2026 19:17
aa5e14d to
e722958
Compare
mafredri
added a commit
that referenced
this pull request
Nov 4, 2026
The section now follows the Deadline() subsection, so it no longer inserts text where #31 and #32 do. The timer and ticker paragraph says what to do instead of how their cleanups work, and the BaseContext advice says to set it on an unstarted server before Start, as the probe that showed srv.Close returning did. On main's timer and ticker code, a reader of C got no tick or value in a cleanup registered before the ticker or the fire, and a reader that also selected on t.Context() exited.
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.
mClock.Trap().WithTimeout()did not catchWithTimeoutCause()calls, andTrap().WithDeadline()did not catchWithDeadlineCause(). A test that trapsWithTimeoutmisses the call if the code under test switches to the cause variant, even though the context created is the same apart from the cause.The
WithTimeoutandWithDeadlinetrappers now catch both variants, andTrapper.WithTimeoutCauseandTrapper.WithDeadlineCauseare removed. They were added in #30 and have not been released.Call.Causestill reports the cause, and it is nil for the non-cause variants. The mock clock's log lines still name the exact function that was called. The README's Contexts section now says which traps to use.A test can no longer trap only the cause variant; a non-nil
Call.Causeshows that a cause variant was called.Stacked on #30.
When squash merging, please replace the commit body with this description.