diff --git a/seaweed-block/cmd/blockvolume/g5_4_l2_replication_test.go b/seaweed-block/cmd/blockvolume/g5_4_l2_replication_test.go index dfc51048cd..bb03d55c8a 100644 --- a/seaweed-block/cmd/blockvolume/g5_4_l2_replication_test.go +++ b/seaweed-block/cmd/blockvolume/g5_4_l2_replication_test.go @@ -223,6 +223,7 @@ func startG54Volume(t *testing.T, bins l2bins, art string, o volOpts) *proc { if o.replicationAck != "" { cmd.Args = append(cmd.Args, "--replication-ack", o.replicationAck) } + stripSystemdForTestLockDir(cmd) cmd.Stdout = lf cmd.Stderr = lf if err := cmd.Start(); err != nil { diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go index 04dec7d25a..b679961e0e 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_integration_test.go @@ -402,7 +402,7 @@ func (h *plannedHandoffHarness) start(t *testing.T, name, binary string, args .. t.Fatal(err) } ctx, cancel := context.WithCancel(context.Background()) - cmd := exec.CommandContext(ctx, binary, args...) + cmd := stripSystemdForTestLockDir(exec.CommandContext(ctx, binary, args...)) cmd.Dir, cmd.Stdout, cmd.Stderr = h.dir, log, log cmd.WaitDelay = 5 * time.Second d := &daemon{name: name, log: log.Name(), done: make(chan struct{}), cancel: cancel} diff --git a/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go b/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go index cc51198a64..6dadcde110 100644 --- a/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go +++ b/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go @@ -118,6 +118,7 @@ func TestBinaryReplicationIngressFollowsAssignedSlots(t *testing.T) { t.Fatal(e) } child := exec.Command(exe, "--master", ln.Addr().String(), "--server-id", "s1", "--volume-id", "v1", "--replica-id", "r1", "--data-addr", data, "--ctrl-addr", ctrl, "--status-addr", status, "--t1-readiness", "--durable-root", root, "--volume-lock-dir-test-only", t.TempDir(), "--durable-impl", "walstore", "--durable-blocks", "64", "--heartbeat-interval", "50ms", "--recovery-mode", mode) + stripSystemdForTestLockDir(child) child.Stdout, child.Stderr = log, log if e = child.Start(); e != nil { t.Fatal(e) diff --git a/seaweed-block/cmd/blockvolume/volume_lock_env_ext_test.go b/seaweed-block/cmd/blockvolume/volume_lock_env_ext_test.go new file mode 100644 index 0000000000..0f08caa197 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/volume_lock_env_ext_test.go @@ -0,0 +1,37 @@ +package main_test + +import ( + "os" + "os/exec" + "strings" +) + +// stripSystemdForTestLockDir is the external test package's copy of the +// helper in volume_lock_env_test.go (package main_test cannot use it): a +// child started with --volume-lock-dir-test-only gets an environment without +// INVOCATION_ID, which a systemd-run test runner would otherwise pass on. +func stripSystemdForTestLockDir(cmd *exec.Cmd) *exec.Cmd { + const flag = "--volume-lock-dir-test-only" + hasFlag := false + for _, a := range cmd.Args[1:] { + if a == flag || strings.HasPrefix(a, flag+"=") { + hasFlag = true + break + } + } + if !hasFlag { + return cmd + } + env := cmd.Env + if env == nil { + env = os.Environ() + } + kept := make([]string, 0, len(env)) + for _, kv := range env { + if !strings.HasPrefix(kv, "INVOCATION_ID=") { + kept = append(kept, kv) + } + } + cmd.Env = kept + return cmd +} diff --git a/seaweed-block/cmd/blockvolume/volume_lock_env_test.go b/seaweed-block/cmd/blockvolume/volume_lock_env_test.go new file mode 100644 index 0000000000..7aa93a3144 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/volume_lock_env_test.go @@ -0,0 +1,37 @@ +package main + +import ( + "os" + "os/exec" + "strings" +) + +// stripSystemdForTestLockDir gives a blockvolume child started with +// --volume-lock-dir-test-only an environment without INVOCATION_ID. +// blockvolume refuses the test override under systemd; a test runner that is +// itself a systemd service (a CI runner unit) would otherwise pass its +// INVOCATION_ID to every child. Other children are left as they are. +func stripSystemdForTestLockDir(cmd *exec.Cmd) *exec.Cmd { + hasFlag := false + for _, a := range cmd.Args[1:] { + if a == "--"+volumeLockDirTestOnlyFlag || strings.HasPrefix(a, "--"+volumeLockDirTestOnlyFlag+"=") { + hasFlag = true + break + } + } + if !hasFlag { + return cmd + } + env := cmd.Env + if env == nil { + env = os.Environ() + } + kept := make([]string, 0, len(env)) + for _, kv := range env { + if !strings.HasPrefix(kv, "INVOCATION_ID=") { + kept = append(kept, kv) + } + } + cmd.Env = kept + return cmd +} diff --git a/seaweed-block/cmd/blockvolume/workspace_lease_binary_test.go b/seaweed-block/cmd/blockvolume/workspace_lease_binary_test.go index 1a2591548b..0ae40371a6 100644 --- a/seaweed-block/cmd/blockvolume/workspace_lease_binary_test.go +++ b/seaweed-block/cmd/blockvolume/workspace_lease_binary_test.go @@ -107,6 +107,7 @@ func TestBinaryWorkspaceLeaseOptInOwnsCLEANShutdown(t *testing.T) { t.Fatal(err) } cmd := exec.Command(exe, "--master", h.Addr(), "--server-id", "node-a", "--volume-id", "vol-a", "--replica-id", "r1", "--data-addr", dataAddr, "--ctrl-addr", ctrlAddr, "--t1-readiness", "--status-addr", statusAddr, "--durable-root", t.TempDir(), "--volume-lock-dir-test-only", t.TempDir(), "--durable-impl", "walstore-chunk", "--durable-blocks", "64", "--chunk-filer", cluster.filerGRPC, "--chunk-path", base, "--chunk-control-endpoint", "--workspace-lease", "--nvme-listen", nvmeAddr, "--nvme-subsysnqn", "nqn.2026-11.test:workspace-lease") + stripSystemdForTestLockDir(cmd) cmd.Stdout, cmd.Stderr = log, log if err = cmd.Start(); err != nil { t.Fatal(err)