test: bound completion waits and diagnostic children and prequeue cleanup

This commit is contained in:
pingqiu committed 2026-11-16 15:50:09 -08:00
1 parent afdead8ad9
commit 58d96e2ba4
4 files changed
+31 -7

No files matched your search

@@ -20,7 +20,10 @@ func BenchmarkQD1PairedBackendSync(b *testing.B) {
b.Run(string(impl), func(b *testing.B) {
id := frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1}
root := b.TempDir()
if out, err := exec.Command("findmnt", "-T", root, "-no", "SOURCE,FSTYPE,TARGET").CombinedOutput(); err == nil {
diagnosticCtx, cancelDiagnostic := context.WithTimeout(context.Background(), 2*time.Second)
out, diagnosticErr := exec.CommandContext(diagnosticCtx, "findmnt", "-T", root, "-no", "SOURCE,FSTYPE,TARGET").CombinedOutput()
cancelDiagnostic()
if diagnosticErr == nil {
fmt.Printf("STUDY_FS %s", out)
}
cfg := durable.ProviderConfig{Impl: impl, StorageRoot: root, NumBlocks: 32768, BlockSize: 4096, ChunkBlocks: 1024}
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/frontend"
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
@@ -65,7 +66,10 @@ func TestQD1BackendSyncCrashReopen(t *testing.T) {
for _, impl := range []durable.ImplName{durable.ImplSmartWAL, durable.ImplWALStoreChunk} {
t.Run(string(impl), func(t *testing.T) {
root := t.TempDir()
cmd := exec.Command(os.Args[0], "-test.run=^TestQD1BackendSyncCrashWriter$", "-test.v")
childCtx, cancelChild := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelChild()
cmd := exec.CommandContext(childCtx, os.Args[0], "-test.run=^TestQD1BackendSyncCrashWriter$", "-test.v")
cmd.WaitDelay = 2 * time.Second
cmd.Env = append(os.Environ(), "QD1_CRASH_IMPL="+string(impl), "QD1_CRASH_ROOT="+root)
out, err := cmd.CombinedOutput()
t.Logf("%s", out)
@@ -2,6 +2,7 @@ package storage
import (
"errors"
"sync"
"sync/atomic"
"testing"
"time"
@@ -42,13 +43,16 @@ func TestDurabilityLatencyCountsSharedPhysicalSyncAndDedup(t *testing.T) {
func TestDurabilityLatencyGroupWaitIsPerRequest(t *testing.T) {
var calls atomic.Uint64
gc := NewGroupCommitter(GroupCommitterConfig{MaxBatch: 2, MaxDelay: time.Second, SyncFunc: func() error { calls.Add(1); return nil }})
var runner sync.Once
startRunner := func() { runner.Do(func() { go gc.Run() }) }
// Failure in prequeue admission must still start a consumer and drain callers.
t.Cleanup(func() { startRunner(); gc.Stop() })
result := make(chan error, 2)
for i := 0; i < 2; i++ {
go func() { result <- gc.SyncCache() }()
}
waitCommitPending(t, gc, 2)
go gc.Run()
defer gc.Stop()
startRunner()
for i := 0; i < 2; i++ {
select {
case err := <-result:
@@ -23,7 +23,7 @@ func TestGroupCommitSingletonStartsWithoutCollectionDelay(t *testing.T) {
case <-time.After(250 * time.Millisecond):
t.Fatal("singleton waited for collection timer before physical sync")
}
if err := <-result; err != nil {
if err := receiveCommitResult(t, result, time.After(2*time.Second)); err != nil {
t.Fatal(err)
}
}
@@ -94,7 +94,7 @@ func TestGroupCommitSingletonFollowersRequireNextPhysicalSync(t *testing.T) {
default:
}
close(releaseFirst)
if err := <-leader; err != nil {
if err := receiveCommitResult(t, leader, time.After(2*time.Second)); err != nil {
t.Fatal(err)
}
select {
@@ -108,8 +108,10 @@ func TestGroupCommitSingletonFollowersRequireNextPhysicalSync(t *testing.T) {
default:
}
close(releaseSecond)
completionDeadline := time.NewTimer(2 * time.Second)
defer completionDeadline.Stop()
for i := 0; i < 8; i++ {
if err := <-followers; !errors.Is(err, failed) {
if err := receiveCommitResult(t, followers, completionDeadline.C); !errors.Is(err, failed) {
t.Fatal("physical error not propagated", err)
}
}
@@ -157,3 +159,14 @@ func TestGroupCommitQD1EveryAckFollowsPhysicalSync(t *testing.T) {
t.Fatal("fsynced bytes differ on reopen", err)
}
}
func receiveCommitResult(t *testing.T, result <-chan error, deadline <-chan time.Time) error {
t.Helper()
select {
case err := <-result:
return err
case <-deadline:
t.Fatal("physical sync started but completion did not settle within deadline")
return nil
}
}