Skip to content

Commit a4f4564

Browse files
ycombinatorclaude
andcommitted
docs: document the freeBlk/reset invariant used by dispatch tests
Add a comment on bulkT.reset noting that only freeBlk should call it, since TestDrainAndFreeAbortedBlkResponse relies on that invariant to use reset as an observable proxy for freeBlk having run. Also split the two concerns in the test comment — synchronous execution (for race-free reads) and the reset-as-proxy assertion — onto separate lines so they're not conflated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3e2fa4c commit a4f4564

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

internal/pkg/bulk/block.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func (a actionT) String() string {
6767
return actionStrings[a]
6868
}
6969

70+
// reset zeros blk's fields so it can be reused from the pool. Only freeBlk
71+
// should call this; tests rely on this invariant to use reset as a proxy
72+
// for observing that freeBlk ran.
7073
func (blk *bulkT) reset() {
7174
blk.action = 0
7275
blk.flags = 0

internal/pkg/bulk/dispatch_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ func TestDrainAndFreeAbortedBlkResponse(t *testing.T) {
9292
blk.ch <- respT{}
9393

9494
// Run synchronously so blk is only touched by this goroutine, making
95-
// the post-drain field reads race-free. blk.reset() is only called
96-
// from freeBlk, so observing the reset proves freeBlk ran.
95+
// the post-drain field reads race-free.
96+
//
97+
// blk.reset() is only called from freeBlk, so observing the reset
98+
// below proves freeBlk ran.
9799
b.drainAndFreeAbortedBlk(blk)
98100

99101
require.Zero(t, blk.action)

0 commit comments

Comments
 (0)