Skip to content

Commit a999079

Browse files
test: build mockstdio_server with isolated cache to prevent flaky CI (#241)
CI occasionally failed with the linker error: /link: cannot open file DO NOT USE - main build pseudo-cache built This is most likely because several parallel `go build` invocations shared the same `$GOCACHE`, letting one job evict the object file another job had promised the linker. The placeholder path then leaked through and the build aborted. This gives each compile its own cache by setting `GOCACHE=$(mktemp -d)` for the helper’s `go build` call. After these changes `go test ./... -race` passed 100/100 consecutive runs locally.
1 parent e40e7a7 commit a999079

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

client/stdio_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ func compileTestServer(outputPath string) error {
2424
outputPath,
2525
"../testdata/mockstdio_server.go",
2626
)
27+
tmpCache, _ := os.MkdirTemp("", "gocache")
28+
cmd.Env = append(os.Environ(), "GOCACHE="+tmpCache)
29+
2730
if output, err := cmd.CombinedOutput(); err != nil {
2831
return fmt.Errorf("compilation failed: %v\nOutput: %s", err, output)
2932
}
33+
// Verify the binary was actually created
3034
if _, err := os.Stat(outputPath); os.IsNotExist(err) {
3135
return fmt.Errorf("mock server binary not found at %s after compilation", outputPath)
3236
}

client/transport/stdio_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ func compileTestServer(outputPath string) error {
2323
outputPath,
2424
"../../testdata/mockstdio_server.go",
2525
)
26+
tmpCache, _ := os.MkdirTemp("", "gocache")
27+
cmd.Env = append(os.Environ(), "GOCACHE="+tmpCache)
28+
2629
if output, err := cmd.CombinedOutput(); err != nil {
2730
return fmt.Errorf("compilation failed: %v\nOutput: %s", err, output)
2831
}

0 commit comments

Comments
 (0)