diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go index af86f04b26..0d0ebdb81c 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -313,6 +313,11 @@ type plannedHandoffHarness struct { dir string master, volume, cli string masterAddr, dataAddr, ctrlAddr, statusAddr, nvmeAddr string + // 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 { @@ -320,7 +325,12 @@ 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} + t.Cleanup(func() { + h.logMu.Lock() + h.logDone = true + h.logMu.Unlock() + }) suffix := "" if isWindows() { suffix = ".exe" @@ -554,6 +564,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 +576,32 @@ 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; after the test ended it logs nothing. +func (h *plannedHandoffHarness) logCommand(args []string, stdout, stderr string, err error) { + h.logMu.Lock() + defer h.logMu.Unlock() + if h.t == nil || h.logDone { + 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: