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..ecb21f52c9 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -773,6 +773,11 @@ 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 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 { admin, io net.Conn r *nvme.Reader @@ -790,7 +795,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) @@ -840,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 { 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")