Skip to content

Commit aeaad24

Browse files
aledbfclaude
andcommitted
test(lifecycle): lock the mock executor against parallel commands
An object hook runs its commands in parallel, so the race detector flagged the unsynchronized record in TestRunHooksErrorNamesTheFailedCommand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5407734 commit aeaad24

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎internal/lifecycle/hooks_test.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@ import (
55
"fmt"
66
"slices"
77
"strings"
8+
"sync"
89
"testing"
910

1011
"github.com/devcontainers/cli/internal/imagemeta"
1112
"github.com/devcontainers/cli/internal/log"
1213
)
1314

15+
// mockExecutor records commands; an object's commands run in parallel, so the
16+
// record is locked.
1417
type mockExecutor struct {
18+
mu sync.Mutex
1519
commands []string
1620
failOn string
1721
}
1822

1923
func (m *mockExecutor) Exec(command string) error {
24+
m.mu.Lock()
2025
m.commands = append(m.commands, command)
26+
m.mu.Unlock()
2127
if m.failOn != "" && strings.Contains(command, m.failOn) {
2228
return fmt.Errorf("command failed: %s", command)
2329
}

0 commit comments

Comments
 (0)