mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: start test-lock-dir children without INVOCATION_ID
A test runner that is itself a systemd service (the CI runner unit) passes its INVOCATION_ID to every child, and blockvolume rightly refuses --volume-lock-dir-test-only under systemd. Every subprocess start that passes the flag now builds the child's environment without INVOCATION_ID (one helper per test package). The product rule is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f9383c5e48
commit
badc7f9596
6 files changed
+78
-1
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user