diff --git a/cmd/micro/cli/new/contract_test.go b/cmd/micro/cli/new/contract_test.go index a8bcbbc017..46e6187a2c 100644 --- a/cmd/micro/cli/new/contract_test.go +++ b/cmd/micro/cli/new/contract_test.go @@ -12,10 +12,17 @@ import ( ) // TestZeroToOneContract locks the documented getting-started path: -// `micro new helloworld` must produce an ordinary Go service that can be -// tested by the Go toolchain. The generated module is pointed back at this -// checkout so the contract stays local and deterministic in CI. +// `micro new helloworld` must produce an ordinary Go service that the Go +// toolchain can build. The generated module is pointed back at this checkout +// so the contract stays local and deterministic in CI. +// +// It shells out to `micro new` (which runs `go mod tidy`) and `go build`, so +// it needs the Go toolchain and module access; it is skipped under `-short`. func TestZeroToOneContract(t *testing.T) { + if testing.Short() { + t.Skip("contract test shells out to the Go toolchain; skipped with -short") + } + repoRoot, err := filepath.Abs(filepath.Join("..", "..", "..", "..")) if err != nil { t.Fatal(err) @@ -59,10 +66,10 @@ func TestZeroToOneContract(t *testing.T) { t.Fatal(err) } - cmd := exec.Command("go", "test", "./...") + cmd := exec.Command("go", "build", "./...") cmd.Dir = serviceDir out, err := cmd.CombinedOutput() if err != nil { - t.Fatalf("generated service go test ./... failed: %v\n%s", err, out) + t.Fatalf("generated service go build ./... failed: %v\n%s", err, out) } } diff --git a/internal/harness/provider-conformance/main.go b/internal/harness/provider-conformance/main.go index a98395b586..8d8151fe98 100644 --- a/internal/harness/provider-conformance/main.go +++ b/internal/harness/provider-conformance/main.go @@ -18,6 +18,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "strings" "time" ) @@ -106,7 +107,26 @@ func runHarness(provider, harness string, timeout time.Duration) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - cmd := exec.CommandContext(ctx, "go", "run", "./internal/harness/"+harness, "-provider", provider) + // Build the harness to a temp binary and run that, rather than `go run`: + // `go run` launches the compiled binary as a child it does not kill on + // context cancellation, so a harness that starts local services could + // outlive the timeout. Running the binary ourselves keeps the timeout + // honest — canceling the context kills the process that does the work. + binDir, err := os.MkdirTemp("", "harness-") + if err != nil { + return err + } + defer os.RemoveAll(binDir) + binPath := filepath.Join(binDir, harness) + + build := exec.CommandContext(ctx, "go", "build", "-o", binPath, "./internal/harness/"+harness) + build.Stdout = os.Stdout + build.Stderr = os.Stderr + if err := build.Run(); err != nil { + return fmt.Errorf("build: %w", err) + } + + cmd := exec.CommandContext(ctx, binPath, "-provider", provider) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Env = localRPCEnv(os.Environ())