From 8ab6ef5ae56423a4bff3bd8397c53a50c7123a45 Mon Sep 17 00:00:00 2001 From: Interlap Date: Wed, 4 Nov 2026 11:22:54 +0100 Subject: [PATCH] test: run the fake xcrun once before timing it macOS vets a newly written executable on its first exec, which took up to 767ms here. TestReadLaunchdRetriesATimedOutRead gives each spawn 200ms, so the first, deliberately hanging attempt was often killed during that check before the script could remove its hang-once marker; the retry then hung too and the test failed (16 of 30 runs). newBatchFake now runs the fake once with its log sent to /dev/null, so short timeouts measure the fake. --- launchd_batch_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/launchd_batch_test.go b/launchd_batch_test.go index be1b17c..6322c67 100644 --- a/launchd_batch_test.go +++ b/launchd_batch_test.go @@ -3,6 +3,7 @@ package simslim import ( "context" "os" + "os/exec" "path/filepath" "reflect" "sort" @@ -171,9 +172,15 @@ func newBatchFake(t *testing.T, runtime string, labels []string, withoutPlist st writeJobPlist(t, filepath.Join(root, "System/Library/LaunchDaemons", l+".plist"), l) } } - if err := os.WriteFile(filepath.Join(dir, "xcrun"), []byte(fakeBatchXcrun), 0o755); err != nil { + xcrun := filepath.Join(dir, "xcrun") + if err := os.WriteFile(xcrun, []byte(fakeBatchXcrun), 0o755); err != nil { t.Fatal(err) } + // macOS vets a new executable on its first exec, which can take most of a + // second; run it once so a short SpawnTimeout times the fake, not that check. + warm := exec.Command(xcrun) + warm.Env = append(os.Environ(), "FAKE_LOG="+os.DevNull) + _ = warm.Run() t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH")) t.Setenv("FAKE_LOG", f.log) t.Setenv("FAKE_DIS", f.dis)