diff --git a/seaweed-block/core/storage/chunk_cut_presync_test.go b/seaweed-block/core/storage/chunk_cut_presync_test.go index 0055173a7a..82b23eb228 100644 --- a/seaweed-block/core/storage/chunk_cut_presync_test.go +++ b/seaweed-block/core/storage/chunk_cut_presync_test.go @@ -350,17 +350,31 @@ func TestAHoldWaitsForAnAdmittedExtentWriteAndHoldsNewOnes(t *testing.T) { held := make(chan func(), 1) go func() { held <- s.holdExtentWrites() }() var release func() - t.Cleanup(func() { // every exit: the admitted write ends, the hold is released, waiters stop + next := make(chan struct{}) // the second worker's end; nil until it starts + var nextStarted bool + // Every exit, before the store's own cleanup: the admitted write ends and + // the hold is released, then each started worker is joined (bounded, a + // timeout reported). Releasing the hold lets the second worker finish; + // stop is closed only after the joins. + t.Cleanup(func() { finish() if release == nil { select { case release = <-held: case <-time.After(ctLocalBound): + t.Error("cleanup: the hold worker did not return") } } if release != nil { release() } + if nextStarted { + select { + case <-next: + case <-time.After(ctLocalBound): + t.Error("cleanup: the held extent-write worker did not finish") + } + } close(stop) }) for deadline := time.Now().Add(ctLocalBound); ; time.Sleep(100 * time.Microsecond) { @@ -384,7 +398,7 @@ func TestAHoldWaitsForAnAdmittedExtentWriteAndHoldsNewOnes(t *testing.T) { t.Fatal("the hold did not return after the admitted write finished") } waits := s.extentHeldWaits.Load() - next := make(chan struct{}) + nextStarted = true go func() { s.admitExtentWrite(stop)(); close(next) }() for deadline := time.Now().Add(ctLocalBound); s.extentHeldWaits.Load() == waits; time.Sleep(100 * time.Microsecond) { select {