From 58d96e2ba46867e839abea328034c23ced3fca65 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 16 Nov 2026 12:29:37 -0800 Subject: [PATCH] test: bound completion waits and diagnostic children and prequeue cleanup --- .../frontend/durable/m5_sync_bench_test.go | 5 ++++- .../frontend/durable/m5_sync_crash_test.go | 6 +++++- .../core/storage/durability_latency_test.go | 8 ++++++-- .../storage/group_commit_singleton_test.go | 19 ++++++++++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/frontend/durable/m5_sync_bench_test.go b/seaweed-block/core/frontend/durable/m5_sync_bench_test.go index 310cc09b64..e1a0cf78e5 100644 --- a/seaweed-block/core/frontend/durable/m5_sync_bench_test.go +++ b/seaweed-block/core/frontend/durable/m5_sync_bench_test.go @@ -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} diff --git a/seaweed-block/core/frontend/durable/m5_sync_crash_test.go b/seaweed-block/core/frontend/durable/m5_sync_crash_test.go index f842f58a93..f7bde4242e 100644 --- a/seaweed-block/core/frontend/durable/m5_sync_crash_test.go +++ b/seaweed-block/core/frontend/durable/m5_sync_crash_test.go @@ -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) diff --git a/seaweed-block/core/storage/durability_latency_test.go b/seaweed-block/core/storage/durability_latency_test.go index 67e59e3eab..0691269676 100644 --- a/seaweed-block/core/storage/durability_latency_test.go +++ b/seaweed-block/core/storage/durability_latency_test.go @@ -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: diff --git a/seaweed-block/core/storage/group_commit_singleton_test.go b/seaweed-block/core/storage/group_commit_singleton_test.go index e620a1417f..460b3e8644 100644 --- a/seaweed-block/core/storage/group_commit_singleton_test.go +++ b/seaweed-block/core/storage/group_commit_singleton_test.go @@ -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 + } +}