From 2095acfd7a608d185a8ba6952e93a916cd5d4221 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 10:05:01 -0800 Subject: [PATCH 1/2] test: red: a slow host's setup and a full-volume read outlast fixed test bounds Two tests fail on a slow host while CI passes (a WSL run with its scratch on a mounted Windows drive). Both fail because a fixed bound in the test, not the product, runs out: - TestWorkspaceRPCSameHostForcedRecoveryRecordsLoss: the successor probe and the later calls run under reviewBindingHostBeforeStart's 10 s context, and a slow setup uses it up ("signal: killed"). The new TestWorkspaceRPCSameHostForcedRecoveryOutlivesASlowSetup pauses 11 s before the probe (both clocks the test reads are fake, so no lease changes) and fails on main on any host. - TestCutoverWriteSnapshotKillRestartRestore: the NVMe initiator sets one deadline at dial (60 s) and requireBlocks then reads all 65,536 blocks on that connection. The new TestNVMeInitiatorDeadlineBoundsEachCommand shortens the deadline (now the variable nvmeIODeadline) to 2 s, idles 2.5 s and reads one block: it fails on main on any host. Co-Authored-By: Claude Opus 5.5 --- .../cutover_end_to_end_integration_test.go | 21 +++++++++++++++++++ .../planned_handoff_integration_test.go | 6 +++++- .../master/workspace_same_host_forced_test.go | 13 +++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/cutover_end_to_end_integration_test.go b/seaweed-block/cmd/blockvolume/cutover_end_to_end_integration_test.go index 3fa7cda4e5..4fa83dfe20 100644 --- a/seaweed-block/cmd/blockvolume/cutover_end_to_end_integration_test.go +++ b/seaweed-block/cmd/blockvolume/cutover_end_to_end_integration_test.go @@ -3,6 +3,7 @@ package main_test import ( + "bytes" "syscall" "testing" "time" @@ -57,6 +58,26 @@ func TestCutoverWriteSnapshotKillRestartRestore(t *testing.T) { env.requireBlocks(t, "s1", 0, ladderLastBlock+1, after) } +// The initiator's deadline bounds each command, not the connection's life: a +// full-volume read loop on a slow host outlasts any fixed bound set at dial. +// A connection idle for longer than the deadline still reads. +func TestNVMeInitiatorDeadlineBoundsEachCommand(t *testing.T) { + env := startCutoverLayoutEnv(t, false) + env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} + source := startCutoverVolume(t, env, "deadline-source", "s1") + env.adopt(t, source, "s1") + env.writeBlock(t, "s1", 5, pattern("deadline-block-A")) + old := nvmeIODeadline + nvmeIODeadline = 2 * time.Second + t.Cleanup(func() { nvmeIODeadline = old }) + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + defer c.close() + time.Sleep(2500 * time.Millisecond) + if got := c.read(t, 5, 4096); !bytes.Equal(got, pattern("deadline-block-A")) { + t.Fatal("the block read after the idle period differs") + } +} + func startCutoverLayoutEnv(t *testing.T, precreateTarget bool) *handoffEnv { t.Helper() return startHandoffEnvConfigured(t, 1, []string{"v2"}, procedureTLSConfig(), precreateTarget) diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go index ac224297cf..35b6afb632 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -773,6 +773,10 @@ func poll(t *testing.T, timeout time.Duration, what string, fn func() bool) { // nvmeInitiator is the smallest NVMe/TCP host the test needs: one admin and // one IO queue, Write, Flush and Read of namespace 1. It runs in the test // process, so the test needs neither root nor the kernel's nvme_tcp. +// nvmeIODeadline bounds the NVMe initiator's connections. A var only so a +// test can shorten it. +var nvmeIODeadline = 60 * time.Second + type nvmeInitiator struct { admin, io net.Conn r *nvme.Reader @@ -790,7 +794,7 @@ func dialNVMe(t *testing.T, addr, subNQN string) *nvmeInitiator { if err != nil { t.Fatalf("nvme dial %s: %v", addr, err) } - _ = conn.SetDeadline(time.Now().Add(60 * time.Second)) + _ = conn.SetDeadline(time.Now().Add(nvmeIODeadline)) r, w := nvme.NewReader(conn), nvme.NewWriter(conn) if err := w.SendHeaderOnly(0x0, &nvme.ICRequest{PDUMaxR2T: 1}, 120); err != nil { t.Fatalf("nvme ICReq: %v", err) diff --git a/seaweed-block/core/host/master/workspace_same_host_forced_test.go b/seaweed-block/core/host/master/workspace_same_host_forced_test.go index 0acd0db260..682cf706aa 100644 --- a/seaweed-block/core/host/master/workspace_same_host_forced_test.go +++ b/seaweed-block/core/host/master/workspace_same_host_forced_test.go @@ -50,7 +50,17 @@ func TestWorkspaceSameHostSuccessorLockProbe(t *testing.T) { } } -func TestWorkspaceRPCSameHostForcedRecoveryRecordsLoss(t *testing.T) { +func TestWorkspaceRPCSameHostForcedRecoveryRecordsLoss(t *testing.T) { sameHostForcedRecovery(t, 0) } + +// A slow host's setup must not use up the time the successor probe and the +// later calls need: the same recovery with an 11 s pause before the probe, +// longer than the helper's former 10 s budget. Both clocks the test reads are +// fake, so the pause changes no lease. +func TestWorkspaceRPCSameHostForcedRecoveryOutlivesASlowSetup(t *testing.T) { + sameHostForcedRecovery(t, 11*time.Second) +} + +func sameHostForcedRecovery(t *testing.T, pause time.Duration) { var nowNS atomic.Int64 nowNS.Store(time.Now().UnixNano()) var observed atomic.Pointer[authority.WorkspaceHead] @@ -135,6 +145,7 @@ func TestWorkspaceRPCSameHostForcedRecoveryRecordsLoss(t *testing.T) { if n, err := backend.Write(ctx, 4096, make([]byte, 4096)); n != 0 || !errors.Is(err, frontend.ErrStalePrimary) { t.Fatalf("live old-epoch process served after the forced barrier: %d %v", n, err) } + time.Sleep(pause) probe := func(locked bool) { t.Helper() cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestWorkspaceSameHostSuccessorLockProbe$", "-test.count=1") From 16c8f868647d3df5ea90c76f5ea390a59aa4727e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 10:05:22 -0800 Subject: [PATCH 2/2] test: bound each NVMe command, and give the review helper a hang guard, not a 10 s budget - The NVMe initiator renews its deadline (nvmeIODeadline, 60 s) before every I/O command, so it bounds each command instead of the connection's whole life: requireBlocks' 65,536 reads no longer race one dial-time deadline. - reviewBindingHostBeforeStart's context is a hang guard for the whole test (60 s, was 10 s), so a slow host's setup does not use up the time the later calls and the successor probe need. TestNVMeInitiatorDeadlineBoundsEachCommand and TestWorkspaceRPCSameHostForcedRecoveryOutlivesASlowSetup pass; test-only, no product change. Co-Authored-By: Claude Opus 5.5 --- .../cmd/blockvolume/planned_handoff_integration_test.go | 6 ++++-- .../core/host/master/workspace_binding_review_test.go | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go index 35b6afb632..ecb21f52c9 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -773,8 +773,9 @@ func poll(t *testing.T, timeout time.Duration, what string, fn func() bool) { // nvmeInitiator is the smallest NVMe/TCP host the test needs: one admin and // one IO queue, Write, Flush and Read of namespace 1. It runs in the test // process, so the test needs neither root nor the kernel's nvme_tcp. -// nvmeIODeadline bounds the NVMe initiator's connections. A var only so a -// test can shorten it. +// nvmeIODeadline bounds each NVMe command of the initiator: it is set at dial +// and renewed before every I/O command, so a long read loop on a slow host is +// not bounded as a whole. A var only so a test can shorten it. var nvmeIODeadline = 60 * time.Second type nvmeInitiator struct { @@ -844,6 +845,7 @@ func nvmeResponse(t *testing.T, r *nvme.Reader) nvme.CapsuleResponse { } func (c *nvmeInitiator) ioCmd(op uint8, lba uint64, blocks int) nvme.CapsuleCommand { + _ = c.io.SetDeadline(time.Now().Add(nvmeIODeadline)) c.cid++ cmd := nvme.CapsuleCommand{OpCode: op, CID: c.cid, NSID: 1} if blocks > 0 { diff --git a/seaweed-block/core/host/master/workspace_binding_review_test.go b/seaweed-block/core/host/master/workspace_binding_review_test.go index 8bcdb786e6..d27f1b96b5 100644 --- a/seaweed-block/core/host/master/workspace_binding_review_test.go +++ b/seaweed-block/core/host/master/workspace_binding_review_test.go @@ -43,7 +43,9 @@ func reviewBindingHostBeforeStart(t *testing.T, reader func(context.Context, str t.Fatal(e) } t.Cleanup(func() { c.Close() }) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + // A hang guard for the whole test, not a performance bound: a slow host's + // setup must not use up the time its later calls need. + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) t.Cleanup(cancel) for _, server := range []string{"node-a", "node-b"} { if _, e = h.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: server, DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); e != nil {