From 4bd3c3b0cecbdd79473a10bf2558f91c685fb627 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 18:38:12 -0800 Subject: [PATCH] test(chunkstore, storage): join every held worker in cleanup Co-Authored-By: Claude Opus 5.5 --- .../chunkstore/chunk_remote_round_test.go | 18 ++++++++++++++++-- .../core/storage/chunk_put_round_test.go | 10 ++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/chunk_remote_round_test.go b/seaweed-block/core/frontend/chunkstore/chunk_remote_round_test.go index bf9e1c5299..a86a5f9e64 100644 --- a/seaweed-block/core/frontend/chunkstore/chunk_remote_round_test.go +++ b/seaweed-block/core/frontend/chunkstore/chunk_remote_round_test.go @@ -395,11 +395,24 @@ func TestChunkRound_ReserveFollowsTheCaller(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() done := make(chan error, 1) + joined := false + t.Cleanup(func() { // ends and joins the worker whatever happens below + cancel() + if joined { + return + } + select { + case <-done: + case <-time.After(10 * time.Second): + t.Error("Put never returned") + } + }) go func() { done <- r.BeginPutRound(1, 4096).Put(ctx, 0, roundKey(0), []byte("x")) }() waitFor(t, entered, "the reservation call") cancel() select { case err := <-done: + joined = true if !errors.Is(err, context.Canceled) { t.Fatalf("cancelled reservation: %v", err) } @@ -494,7 +507,7 @@ func TestChunkRound_StaleReplacementIsDiscarded(t *testing.T) { t.Cleanup(func() { // release and join every worker started releaseAll() cancel() - for k := 0; k < started; k++ { + for ; started > 0; started-- { select { case <-errs: case <-time.After(10 * time.Second): @@ -523,9 +536,10 @@ func TestChunkRound_StaleReplacementIsDiscarded(t *testing.T) { time.Sleep(time.Millisecond) } releaseAll() - for ; started > 0; started-- { + for started > 0 { select { case err := <-errs: + started-- // joined, before any Fatal: cleanup must not wait for it again if err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/storage/chunk_put_round_test.go b/seaweed-block/core/storage/chunk_put_round_test.go index bb1aaeb862..cb597c9b57 100644 --- a/seaweed-block/core/storage/chunk_put_round_test.go +++ b/seaweed-block/core/storage/chunk_put_round_test.go @@ -232,13 +232,14 @@ func TestChunkCut_HeldRoundCallIsJoined(t *testing.T) { w.write(t, s, 2, 0x22) cutDone := make(chan error, 1) closeDone := make(chan error, 1) - closeStarted := false - t.Cleanup(func() { // release, then join every worker started + guest := make(chan error, 1) + closeStarted, guestStarted := false, false + t.Cleanup(func() { // release, then join every worker started and not yet joined release() for _, c := range []struct { ch chan error started bool - }{{cutDone, true}, {closeDone, closeStarted}} { + }{{cutDone, true}, {closeDone, closeStarted}, {guest, guestStarted}} { if !c.started { continue } @@ -252,7 +253,7 @@ func TestChunkCut_HeldRoundCallIsJoined(t *testing.T) { go func() { _, err := layer.Cut(context.Background()); cutDone <- err }() waitDone(t, h.entered, "the cut's upload call") - guest := make(chan error, 1) + guestStarted = true go func() { if _, err := s.Write(7, makeBlock(ctBlockSize, 0x77)); err != nil { guest <- err @@ -263,6 +264,7 @@ func TestChunkCut_HeldRoundCallIsJoined(t *testing.T) { }() select { case err := <-guest: + guestStarted = false // joined if err != nil { t.Fatalf("guest write/flush during the held upload: %v", err) }