plugin tests: TestHostRunsAsMagpieBun puts the Bun on PATH at the old name as a hard link, not a fresh copy, so macOS's first-run check of a new program no longer comes out of the host's one-minute start under a full go test run (#1306)
A copy is a new program, which macOS checks before its first exec; the host's init ran it inside the test's minute. Timed here with load ~130 and syspolicyd not pegged: a fresh copy's first `--version` took 0.9-1.6s, a hard link of the same bun 0.04-0.3s; with syspolicyd busy the same check took 26-55s a program in #1284. Where no link can be made (another filesystem), the copy is run once before the minute starts. Run in Docker (golang:1.26.8, linux/arm64, bun 1.4.2): -count=3 of the test with bun on a bind mount (copy path) and beside HOME (link path), all PASS; go test -tags nogui ./internal/plugin ok; go vet for linux, windows and darwin clean. Not run: the test on macOS itself (Go tests are kept off this Mac while syspolicyd is overloaded), so the red under a slow first-run check is shown by the timings above, not by a failing run.
This commit is contained in:
1 parent
1e405be3fc
commit
7ddea2c2e0
1 file changed
+20
-3
@@ -65,13 +65,13 @@ func TestHostRunsAsMagpieBun(t *testing.T) {
|
||||
}
|
||||
bunHome(t, BunVersion, time.Now())
|
||||
t.Cleanup(Settle)
|
||||
// a real Bun as magpie downloaded it before: a copy (not a link, whose
|
||||
// process would take the target's name) at the old name
|
||||
// a real Bun as magpie downloaded it before, at the old name: a hard
|
||||
// link, not a symlink (whose process would take the target's name)
|
||||
old := filepath.Join(bunDirOf(BunVersion), bunExe())
|
||||
if err := os.MkdirAll(filepath.Dir(old), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
copyExe(t, real, old)
|
||||
placeBun(t, real, old)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
@@ -103,6 +103,23 @@ func TestHostRunsAsMagpieBun(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// placeBun puts the Bun at from at to, as a file that has run before. A
|
||||
// hard link is the Bun on PATH itself, which has. A copy is a new program,
|
||||
// and macOS checks a new program before its first run: a second alone,
|
||||
// tens of seconds while a go test ./... starts its test binaries, which
|
||||
// came out of the host's start and its minute (#1306). So a copy, where
|
||||
// no link can be made, is run once here, before that minute starts.
|
||||
func placeBun(t *testing.T, from, to string) {
|
||||
t.Helper()
|
||||
if src, err := filepath.EvalSymlinks(from); err == nil && os.Link(src, to) == nil {
|
||||
return
|
||||
}
|
||||
copyExe(t, from, to)
|
||||
if out, err := exec.Command(to, "--version").CombinedOutput(); err != nil {
|
||||
t.Fatalf("the copied bun: %v %s", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func copyExe(t *testing.T, from, to string) {
|
||||
t.Helper()
|
||||
in, err := os.Open(from)
|
||||
|
||||
Reference in new issue
Block a user