Skip to content

Commit

Permalink
Reduce flakiness of fdo.command FSIM test
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Krieger <[email protected]>
  • Loading branch information
ben-krieger committed Oct 18, 2024
1 parent ec4e164 commit 5b993c5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions fsim/command_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,17 @@ func (c *Command) Yield(ctx context.Context, respond func(message string) io.Wri
// Check exited before writing any output to avoid race conditions where
// output is lost if process exits between writing stdout/stderr and the
// exited check
exited := c.cmd.ProcessState != nil
var exited bool
select {
case err := <-c.errc:
defer c.reset()
exited = true

if err != nil {
return fmt.Errorf("command failed to execute: %w", err)
}
default:
}

// Send any data on the stdout/stderr pipes
if c.stdout {
Expand All @@ -183,11 +193,6 @@ func (c *Command) Yield(ctx context.Context, respond func(message string) io.Wri
}

// Handle process exit
defer c.reset()

if err := <-c.errc; err != nil {
return fmt.Errorf("command failed to execute: %w", err)
}
code := c.cmd.ProcessState.ExitCode()
if code != 0 && !c.mayFail {
return fmt.Errorf("command failed with exit code: %d", code)
Expand Down

0 comments on commit 5b993c5

Please sign in to comment.