Skip to content

Commit 6de39e2

Browse files
Add protection for git operations
1 parent 4012aba commit 6de39e2

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

dgraphtest/image.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
var (
2323
cloneOnce sync.Once
24+
gitMutex sync.Mutex // Protects git operations on shared repoDir
2425
)
2526

2627
func (c *LocalCluster) dgraphImage() string {
@@ -49,7 +50,23 @@ func (c *LocalCluster) setupBinary() error {
4950
return copyBinary(fromDir, c.tempBinDir, c.conf.version)
5051
}
5152

52-
isFileThere, err := fileExists(filepath.Join(binariesPath, fmt.Sprintf(binaryNameFmt, c.conf.version)))
53+
binaryPath := filepath.Join(binariesPath, fmt.Sprintf(binaryNameFmt, c.conf.version))
54+
55+
// First check without lock (fast path)
56+
isFileThere, err := fileExists(binaryPath)
57+
if err != nil {
58+
return err
59+
}
60+
if isFileThere {
61+
return copyBinary(binariesPath, c.tempBinDir, c.conf.version)
62+
}
63+
64+
// Lock git operations to prevent parallel tests from conflicting
65+
gitMutex.Lock()
66+
defer gitMutex.Unlock()
67+
68+
// Double-check after acquiring lock - another parallel test may have built it
69+
isFileThere, err = fileExists(binaryPath)
5370
if err != nil {
5471
return err
5572
}

0 commit comments

Comments
 (0)