Skip to content

fix: copy tags passed to mock clock calls and traps - #42

Draft
mafredri wants to merge 2 commits into
mafredri/go-1.26from
mafredri/call-tags-copy
Draft

mafredri wants to merge 2 commits into
mafredri/go-1.26from
mafredri/call-tags-copy

Conversation

@mafredri

@mafredri mafredri commented Nov 4, 2026

Copy link
Copy Markdown
Member

The mock clock kept the caller's tags slice instead of a copy. If code under test reuses its slice after mClock.Now(tags...) returns, a test that reads call.Tags after release, as the README shows, races with that write and can see the new values. The same applies to Trap().Now(tags...): changing the slice afterward changes which calls the trap matches.

TestTags_CallerReusesSlice reuses the trap's slice after Trap().Now returns and the call's slice after Now returns, then checks call.Tags. Without the trap copy, the trap matches nothing and the test times out. Without the call copy, call.Tags is [reused].

#36 and #32 work around this locally (#36 describes the call before releasing it; #32 clones the call's tags); they can drop those workarounds after this lands.

Stacked on #41.

🤖 This PR was created with the help of Coder Agents.

newCall and newTrap kept the caller's variadic tags slice. Code that
reused its slice after a clock call returned raced with a test reading
Call.Tags, and the test saw the new values. Reusing a slice passed to
Trap().Now(...) also changed which calls the trap matched.
Test_MultipleTraps covers releasing a call caught by two traps. Tag
slice reuse is a separate behavior, so it gets its own test and
Test_MultipleTraps goes back to its original form.
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.

1 participant