test(chunkstore, storage): join every held worker in cleanup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-20 18:38:12 -08:00
1 parent a89eb5c9cb
commit 4bd3c3b0ce
2 files changed
+22 -6

No files matched your search

@@ -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)
}
@@ -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)
}