Skip to content

Commit ab03a63

Browse files
committed
Fix nondeterministic behavior
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
1 parent ba1acf5 commit ab03a63

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Diff for: modules/git/command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (c *Command) RunInDirTimeoutEnvFullPipelineFunc(env []string, timeout time.
138138
fn(ctx, cancel)
139139
}
140140

141-
if err := cmd.Wait(); err != nil {
141+
if err := cmd.Wait(); err != nil && ctx.Err() != context.DeadlineExceeded {
142142
return err
143143
}
144144

Diff for: modules/git/command_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
3030
maxLoops := 1000
3131

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

0 commit comments

Comments
 (0)