-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from mykso/unique-tmp-dir
Fix race condition when running multiple vendir from the same directory
- Loading branch information
Showing
3 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConcurrentProcesses(t *testing.T) { | ||
env := BuildEnv(t) | ||
logger := Logger{} | ||
vendir := Vendir{t, env.BinaryPath, logger} | ||
tmpRoot := t.TempDir() | ||
processes := 2 | ||
|
||
yaml := ` | ||
apiVersion: vendir.k14s.io/v1alpha1 | ||
kind: Config | ||
directories: | ||
- path: vendor/dest-%d | ||
contents: | ||
- path: . | ||
git: | ||
url: https://github.com/carvel-dev/ytt | ||
ref: v0.27.x | ||
depth: 1 | ||
includePaths: | ||
- README.md | ||
- pkg/version/version.go` | ||
|
||
logger.Section("execute several vendir processes concurrently", func() { | ||
wg := sync.WaitGroup{} | ||
for i := 0; i < processes; i++ { | ||
wg.Add(1) | ||
go func(n int, t *testing.T, wg *sync.WaitGroup) { | ||
defer wg.Done() | ||
// RunWithOpts invokes t.Fatal on error | ||
vendir.RunWithOpts( | ||
[]string{"sync", "-f", "-"}, | ||
RunOpts{ | ||
Dir: tmpRoot, | ||
StdinReader: strings.NewReader(fmt.Sprintf(yaml, n)), | ||
}) | ||
}(i, t, &wg) | ||
} | ||
wg.Wait() | ||
for i := 0; i < processes; i++ { | ||
_, err := os.Stat(fmt.Sprintf("%s/vendor/dest-%d/README.md", tmpRoot, i)) | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} |