Skip to content

Commit

Permalink
Fix nondeterministic behavior (#9341)
Browse files Browse the repository at this point in the history
The underlying implementation of os.exec uses channels and goroutines.
It is possible to have time-variant error values returned from Cmd.Wait
depending on which comes first.

Also, the git subcommand and options should be separated tokens.

Fixes a flaky test in modules/git/command_test.go
  • Loading branch information
typeless authored and lunny committed Dec 13, 2019
1 parent 39db99a commit 6e6936d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/git/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (c *Command) RunInDirTimeoutEnvFullPipelineFunc(env []string, timeout time.
fn(ctx, cancel)
}

if err := cmd.Wait(); err != nil {
if err := cmd.Wait(); err != nil && ctx.Err() != context.DeadlineExceeded {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion modules/git/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
maxLoops := 1000

// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
cmd := NewCommand("hash-object --stdin")
cmd := NewCommand("hash-object", "--stdin")
for i := 0; i < maxLoops; i++ {
if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil {
if err != context.DeadlineExceeded {
Expand Down

0 comments on commit 6e6936d

Please sign in to comment.