Skip to content

Commit

Permalink
cmd: fix test flakyiness (#6040)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks authored Feb 10, 2023
1 parent dcc0d08 commit 179ba4c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/controllers/core/cmd/execer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Execer interface {
}

type fakeExecProcess struct {
closeCh chan bool
exitCh chan int
workdir string
env []string
Expand All @@ -47,17 +48,23 @@ func NewFakeExecer() *FakeExecer {

func (e *FakeExecer) Start(ctx context.Context, cmd model.Cmd, w io.Writer) chan statusAndMetadata {
e.mu.Lock()
_, ok := e.processes[cmd.String()]
oldProcess, ok := e.processes[cmd.String()]
e.mu.Unlock()
if ok {
logger.Get(ctx).Infof("internal error: fake execer only supports one instance of each unique command at a time. tried to start a second instance of %q", cmd.Argv)
return nil
select {
case <-oldProcess.closeCh:
case <-time.After(5 * time.Second):
logger.Get(ctx).Infof("internal error: fake execer only supports one instance of each unique command at a time. tried to start a second instance of %q", cmd.Argv)
return nil
}
}

exitCh := make(chan int)
closeCh := make(chan bool)

e.mu.Lock()
e.processes[cmd.String()] = &fakeExecProcess{
closeCh: closeCh,
exitCh: exitCh,
workdir: cmd.Dir,
startTime: time.Now(),
Expand All @@ -70,6 +77,7 @@ func (e *FakeExecer) Start(ctx context.Context, cmd model.Cmd, w io.Writer) chan
fakeRun(ctx, cmd, w, statusCh, exitCh)

e.mu.Lock()
close(closeCh)
delete(e.processes, cmd.String())
e.mu.Unlock()
}()
Expand Down

0 comments on commit 179ba4c

Please sign in to comment.