Skip to content

Commit 1d04210

Browse files
committed
Isolate pack builder PACK_HOME for parallel test execution
Parallel func deploy calls with the pack builder corrupt the shared ~/.pack/volume-keys.toml file, causing deterministic failures. Create a per-deploy temporary PACK_HOME directory when using the pack builder via the new EnvVars deploy option.
1 parent 00151b3 commit 1d04210

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

test/utils/func.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, erro
8181
args = append(args, "--deployer", opts.Deployer)
8282
}
8383

84+
// When using the pack builder, create a per-deploy PACK_HOME to prevent
85+
// parallel builds from corrupting the shared ~/.pack/volume-keys.toml.
86+
if opts.Builder == "pack" {
87+
packHome, err := os.MkdirTemp("", "pack-home-*")
88+
if err != nil {
89+
return "", fmt.Errorf("failed to create PACK_HOME: %w", err)
90+
}
91+
defer os.RemoveAll(packHome)
92+
93+
if opts.EnvVars == nil {
94+
opts.EnvVars = make(map[string]string)
95+
}
96+
opts.EnvVars["PACK_HOME"] = packHome
97+
}
98+
8499
var output string
85100
var err error
86101

@@ -96,12 +111,22 @@ func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, erro
96111
retryDelay *= 2
97112
}
98113

114+
var funcBinary string
99115
if opts.CliVersion != "" {
100-
output, err = RunFuncWithVersion(opts.CliVersion, "deploy", args...)
116+
funcBinary, err = ensureFuncVersion(opts.CliVersion)
117+
if err != nil {
118+
return "", err
119+
}
101120
} else {
102-
output, err = RunFunc("deploy", args...)
121+
funcBinary = "func"
103122
}
104123

124+
cmd := exec.Command(funcBinary, append([]string{"deploy"}, args...)...)
125+
for k, v := range opts.EnvVars {
126+
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
127+
}
128+
output, err = Run(cmd)
129+
105130
if err == nil {
106131
return output, nil
107132
}
@@ -117,6 +142,7 @@ type FuncDeployOptions struct {
117142
Builder string
118143
Deployer string
119144
CliVersion string
145+
EnvVars map[string]string
120146
}
121147

122148
type FuncDeployOption func(*FuncDeployOptions)
@@ -145,6 +171,12 @@ func WithDeployCliVersion(version string) FuncDeployOption {
145171
}
146172
}
147173

174+
func WithEnvVars(envVars map[string]string) FuncDeployOption {
175+
return func(opts *FuncDeployOptions) {
176+
opts.EnvVars = envVars
177+
}
178+
}
179+
148180
// ensureFuncVersion ensures the specified func version is available and returns its path
149181
func ensureFuncVersion(version string) (string, error) {
150182
projectDir, err := GetProjectDir()

test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Run(cmd *exec.Cmd) (string, error) {
3636
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
3737
}
3838

39-
cmd.Env = append(os.Environ(), "GO111MODULE=on")
39+
cmd.Env = append(append(os.Environ(), cmd.Env...), "GO111MODULE=on")
4040
command := strings.Join(cmd.Args, " ")
4141
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
4242
output, err := cmd.CombinedOutput()

0 commit comments

Comments
 (0)