test: count comparison callbacks atomically

This commit is contained in:
pingqiu committed 2026-11-29 16:03:46 -08:00
1 parent 3aff8010d7
commit 4899e42e6f
1 file changed
+5 -4
@@ -3,6 +3,7 @@ package storage
import (
"bytes"
"errors"
"sync/atomic"
"testing"
)
@@ -37,10 +38,10 @@ func TestRefusedFullCutStagesOnlyTheUnmarkedChunk(t *testing.T) {
// The next pass can expose less than one chunk at its barrier. Staging
// therefore has to process every actual candidate, making its count exact.
l.cfg.COWSpillFree = func() (int64, error) { return 2 * (cowSpillFreeReserve + ctChunkBytes), nil }
comparedAgain := 0
var comparedAgain atomic.Int64
l.testAfterCompareHook = func(idx uint64) {
if marked[idx] {
comparedAgain++
comparedAgain.Add(1)
}
}
result, err := l.Cut(ctTimeout(t))
@@ -50,8 +51,8 @@ func TestRefusedFullCutStagesOnlyTheUnmarkedChunk(t *testing.T) {
if result.Stats.StagedChunks != 1 {
t.Fatalf("retry staged %d chunks, want only the one unmarked chunk", result.Stats.StagedChunks)
}
if comparedAgain != 0 || result.Stats.CandidateChunks != 1 {
t.Fatalf("retry compared %d candidates (%d already equal), want 1 and 0", result.Stats.CandidateChunks, comparedAgain)
if comparedAgain.Load() != 0 || result.Stats.CandidateChunks != 1 {
t.Fatalf("retry compared %d candidates (%d already equal), want 1 and 0", result.Stats.CandidateChunks, comparedAgain.Load())
}
if !bytes.Equal(blockOf(f.imageOf(t, result.Head), ctChunkBlocks+1), want) {
t.Fatal("retry lost changed bytes")