From 320fbc84110f11c23b648903744111397ea3db67 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 12:40:02 -0800 Subject: [PATCH 1/2] test(blockvolume): the procedure harness logs every sw-block command h.run and runCLI write each command's argv, exit status and output (each stream capped at 4 KiB) to the test log, so a refusal is visible without a rerun. Co-Authored-By: Claude Opus 5.5 --- .../planned_handoff_integration_test.go | 29 ++++++++++++++++++- .../snapshot_ladder_integration_test.go | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go index af86f04b26..ff476de122 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -313,6 +313,8 @@ type plannedHandoffHarness struct { dir string master, volume, cli string masterAddr, dataAddr, ctrlAddr, statusAddr, nvmeAddr string + // t logs every sw-block command (logCommand). + t *testing.T } func newPlannedHandoffHarness(t *testing.T) *plannedHandoffHarness { @@ -320,7 +322,7 @@ func newPlannedHandoffHarness(t *testing.T) *plannedHandoffHarness { if os.Getenv("CHUNKSTORE_WEED") == "" { t.Fatal("CHUNKSTORE_WEED must name the pinned real SeaweedFS binary") } - h := &plannedHandoffHarness{dir: t.TempDir()} + h := &plannedHandoffHarness{dir: t.TempDir(), t: t} suffix := "" if isWindows() { suffix = ".exe" @@ -554,6 +556,7 @@ func (h *plannedHandoffHarness) run(t *testing.T, args ...string) (string, strin cmd.Stdout, cmd.Stderr = &stdout, &stderr err := cmd.Run() captureOutput(t, args, stdout.String(), stderr.String()) + h.logCommand(args, stdout.String(), stderr.String(), err) var exit *exec.ExitError switch { case err == nil: @@ -565,6 +568,30 @@ func (h *plannedHandoffHarness) run(t *testing.T, args ...string) (string, strin return "", "", -1 } +// logCommandCap bounds each logged stream of one sw-block command. +const logCommandCap = 4096 + +// logCommand writes one sw-block command's argv, exit status and output to +// the test log, so a refusal is visible without a rerun. It is safe from the +// goroutines runCLI runs on while the test is running. +func (h *plannedHandoffHarness) logCommand(args []string, stdout, stderr string, err error) { + if h.t == nil { + return + } + status := "exit 0" + if err != nil { + status = err.Error() + } + h.t.Logf("sw-block %q: %s\nstdout: %s\nstderr: %s", args, status, capLog(stdout), capLog(stderr)) +} + +func capLog(s string) string { + if len(s) <= logCommandCap { + return s + } + return s[:logCommandCap] + fmt.Sprintf("... (%d more bytes)", len(s)-logCommandCap) +} + // waitPrimary polls the status endpoint until the volume serves as a // healthy primary at epoch. func (h *plannedHandoffHarness) waitPrimary(t *testing.T, epoch uint64) { diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go index 928d509adb..3354bd49fc 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go @@ -537,6 +537,7 @@ func runCLI(ctx context.Context, h *plannedHandoffHarness, args ...string) (stri var stdout, stderr strings.Builder cmd.Stdout, cmd.Stderr = &stdout, &stderr err := cmd.Run() + h.logCommand(args, stdout.String(), stderr.String(), err) var exit *exec.ExitError switch { case err == nil: From 3f7c1e40d630f2dda9b88d9ad87a83372b206149 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 12:42:17 -0800 Subject: [PATCH 2/2] test(blockvolume): the command log stops at the test's end A runCLI goroutine that outlives its test would make t.Logf panic; a done flag set in t.Cleanup turns logCommand into a no-op from then on. Co-Authored-By: Claude Opus 5.5 --- .../planned_handoff_integration_test.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go index ff476de122..0d0ebdb81c 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -313,8 +313,11 @@ type plannedHandoffHarness struct { dir string master, volume, cli string masterAddr, dataAddr, ctrlAddr, statusAddr, nvmeAddr string - // t logs every sw-block command (logCommand). - t *testing.T + // t logs every sw-block command (logCommand) until the test ends + // (logDone): a runCLI goroutine that outlives it must not call t.Logf. + t *testing.T + logMu sync.Mutex + logDone bool } func newPlannedHandoffHarness(t *testing.T) *plannedHandoffHarness { @@ -323,6 +326,11 @@ func newPlannedHandoffHarness(t *testing.T) *plannedHandoffHarness { t.Fatal("CHUNKSTORE_WEED must name the pinned real SeaweedFS binary") } h := &plannedHandoffHarness{dir: t.TempDir(), t: t} + t.Cleanup(func() { + h.logMu.Lock() + h.logDone = true + h.logMu.Unlock() + }) suffix := "" if isWindows() { suffix = ".exe" @@ -573,9 +581,11 @@ const logCommandCap = 4096 // logCommand writes one sw-block command's argv, exit status and output to // the test log, so a refusal is visible without a rerun. It is safe from the -// goroutines runCLI runs on while the test is running. +// goroutines runCLI runs on; after the test ended it logs nothing. func (h *plannedHandoffHarness) logCommand(args []string, stdout, stderr string, err error) { - if h.t == nil { + h.logMu.Lock() + defer h.logMu.Unlock() + if h.t == nil || h.logDone { return } status := "exit 0"