mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: count comparison callbacks atomically
This commit is contained in:
1 parent
3aff8010d7
commit
4899e42e6f
1 file changed
+5
-4
@@ -3,6 +3,7 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,10 +38,10 @@ func TestRefusedFullCutStagesOnlyTheUnmarkedChunk(t *testing.T) {
|
|||||||
// The next pass can expose less than one chunk at its barrier. Staging
|
// The next pass can expose less than one chunk at its barrier. Staging
|
||||||
// therefore has to process every actual candidate, making its count exact.
|
// therefore has to process every actual candidate, making its count exact.
|
||||||
l.cfg.COWSpillFree = func() (int64, error) { return 2 * (cowSpillFreeReserve + ctChunkBytes), nil }
|
l.cfg.COWSpillFree = func() (int64, error) { return 2 * (cowSpillFreeReserve + ctChunkBytes), nil }
|
||||||
comparedAgain := 0
|
var comparedAgain atomic.Int64
|
||||||
l.testAfterCompareHook = func(idx uint64) {
|
l.testAfterCompareHook = func(idx uint64) {
|
||||||
if marked[idx] {
|
if marked[idx] {
|
||||||
comparedAgain++
|
comparedAgain.Add(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result, err := l.Cut(ctTimeout(t))
|
result, err := l.Cut(ctTimeout(t))
|
||||||
@@ -50,8 +51,8 @@ func TestRefusedFullCutStagesOnlyTheUnmarkedChunk(t *testing.T) {
|
|||||||
if result.Stats.StagedChunks != 1 {
|
if result.Stats.StagedChunks != 1 {
|
||||||
t.Fatalf("retry staged %d chunks, want only the one unmarked chunk", result.Stats.StagedChunks)
|
t.Fatalf("retry staged %d chunks, want only the one unmarked chunk", result.Stats.StagedChunks)
|
||||||
}
|
}
|
||||||
if comparedAgain != 0 || result.Stats.CandidateChunks != 1 {
|
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)
|
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) {
|
if !bytes.Equal(blockOf(f.imageOf(t, result.Head), ctChunkBlocks+1), want) {
|
||||||
t.Fatal("retry lost changed bytes")
|
t.Fatal("retry lost changed bytes")
|
||||||
|
|||||||
Reference in new issue
Block a user