Repository navigation
Conversation
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.
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.
The mock clock kept the caller's
tagsslice instead of a copy. If code under test reuses its slice aftermClock.Now(tags...)returns, a test that readscall.Tagsafter release, as the README shows, races with that write and can see the new values. The same applies toTrap().Now(tags...): changing the slice afterward changes which calls the trap matches.TestTags_CallerReusesSlicereuses the trap's slice afterTrap().Nowreturns and the call's slice afterNowreturns, then checkscall.Tags. Without the trap copy, the trap matches nothing and the test times out. Without the call copy,call.Tagsis[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.