carlos / platform Public

activator tests: the recording scripts put their files in place whole

TestExecBackendStartWorkerEnvWinsOverTenantFile failed twice in full
gate runs tonight, on commits that do not touch this package. Its child
script recorded its environment with `env > path`. The shell creates
path, empty, before env writes, and the test, polling for the file, could
read it in that moment and find no variables.

Both recording scripts now write beside the path and rename into place,
so the file is either absent or whole.

Measured with sixteen copies of the test binary running the two
recording tests forty times each, twice (1,280 runs under that load):
55 failures before, none after. The whole package passes.

A test-only change, separate from the review rounds.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev bac513f6bd3e1cc4bbc459083d2bf5e015c74f33 parent cd8821c
1 file changed, +16 −5
  • internal/activator/activator_test.go +16 −5
diff --git a/internal/activator/activator_test.go b/internal/activator/activator_test.go
index e2cc159aa..c27ccd6ca 100644
--- a/internal/activator/activator_test.go
+++ b/internal/activator/activator_test.go
@@ -4720,8 +4720,8 @@ func stageRecordingLive(t *testing.T, b *ExecBackend, host, ver string) (argvPat
argvPath = filepath.Join(dir, "argv")
envPath = filepath.Join(dir, "env")
script := "#!/bin/sh\n" +
- "printf '%s\\n' \"$@\" > '" + argvPath + "'\n" +
- "printf '%s\\n' \"${CARLOS_CONTROL_SOCKET-<unset>}\" > '" + envPath + "'\n"
+ recordTo("printf '%s\\n' \"$@\"", argvPath) +
+ recordTo("printf '%s\\n' \"${CARLOS_CONTROL_SOCKET-<unset>}\"", envPath)
vdir := filepath.Join(b.OptDir, "versions", ver)
if err := os.MkdirAll(vdir, 0o755); err != nil {
@@ -4753,8 +4753,8 @@ func stageRecordingLiveFullEnv(t *testing.T, b *ExecBackend, host, ver string) (
argvPath = filepath.Join(dir, "argv")
envPath = filepath.Join(dir, "env")
script := "#!/bin/sh\n" +
- "printf '%s\\n' \"$@\" > '" + argvPath + "'\n" +
- "env > '" + envPath + "'\n"
+ recordTo("printf '%s\\n' \"$@\"", argvPath) +
+ recordTo("env", envPath)
vdir := filepath.Join(b.OptDir, "versions", ver)
if err := os.MkdirAll(vdir, 0o755); err != nil {
@@ -4774,8 +4774,19 @@ func stageRecordingLiveFullEnv(t *testing.T, b *ExecBackend, host, ver string) (
return argvPath, envPath
}
+// recordTo is one line of a recording script: run command and leave its
+// output at path. The output is written beside path and renamed into place.
+// A plain `command > path` creates path, empty, before the command has
+// written a byte, and a test polling for the file with waitForFile could
+// read it in that moment and see nothing. A rename is atomic, so the file
+// either is not there or is whole.
+func recordTo(command, path string) string {
+ return command + " > '" + path + ".part' && mv '" + path + ".part' '" + path + "'\n"
+}
+
// waitForFile polls until path exists (the child writes it concurrently with
-// Start's health wait) and returns its contents.
+// Start's health wait) and returns its contents. The recording scripts put
+// the file in place whole (recordTo), so what is read is never partial.
func waitForFile(t *testing.T, path string, within time.Duration) string {
t.Helper()
deadline := time.Now().Add(within)