Fix nondeterministic behavior (#9341)

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
tokarchuk/v1.17
Mura Li 5 years ago committed by Lunny Xiao
parent 39db99a595
commit 6e6936d73d
  1. 2
      modules/git/command.go
  2. 2
      modules/git/command_test.go

@ -138,7 +138,7 @@ func (c *Command) RunInDirTimeoutEnvFullPipelineFunc(env []string, timeout time.
fn(ctx, cancel) fn(ctx, cancel)
} }
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil && ctx.Err() != context.DeadlineExceeded {
return err return err
} }

@ -30,7 +30,7 @@ func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
maxLoops := 1000 maxLoops := 1000
// 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered. // '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++ { for i := 0; i < maxLoops; i++ {
if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil { if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil {
if err != context.DeadlineExceeded { if err != context.DeadlineExceeded {

Loading…
Cancel
Save