From dd38de086c6b9cfebe6cd3bc07af6162734f8e7a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 01:26:58 -0800 Subject: [PATCH] test(storage): prevent retries from bypassing takeover cooling --- .../core/storage/chunk_head_belt_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/seaweed-block/core/storage/chunk_head_belt_test.go b/seaweed-block/core/storage/chunk_head_belt_test.go index c9d9c0c35d..ea1f47ca93 100644 --- a/seaweed-block/core/storage/chunk_head_belt_test.go +++ b/seaweed-block/core/storage/chunk_head_belt_test.go @@ -147,3 +147,22 @@ func TestHeadBeltConfirmationUsesOnlyRoot(t *testing.T) { t.Fatal("confirmed wrong image") } } + +func TestHeadBeltRetryOfUnconfirmedClaimStillCools(t *testing.T) { + f := newFakeChunkRemote() + f.head = chunkHead{Gen: 1, Epoch: 1, Holder: "old", Chunks: map[uint64]chunkRef{}} + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + defer cancel() + if _, err := ClaimChunkHead(ctx, f, ChunkLayerConfig{Epoch: 2, Holder: "new"}); !errors.Is(err, context.DeadlineExceeded) || f.stats().cas != 1 { + t.Fatalf("claim did not stop inside cooling after CAS: %v, calls=%d", err, f.stats().cas) + } + retryCtx, retryCancel := context.WithTimeout(context.Background(), 8*time.Second) + defer retryCancel() + start := time.Now() + if _, err := ClaimChunkHead(retryCtx, f, ChunkLayerConfig{Epoch: 2, Holder: "new"}); err != nil { + t.Fatal(err) + } + if time.Since(start) < 5*time.Second || f.stats().cas != 1 { + t.Fatal("retry bypassed cooling or replayed a settled claim") + } +}