This repository was archived by the owner on Sep 11, 2020. It is now read-only.
transport/file: fix race condition on test #267
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes, the
TestClone
andTestPush
tests oftransport/file
failin travis.
This is due to a race condition caused by an incorrect usage of
Cmd.Wait()
while reading from the output and error pipes of thecommand.
This patch fixes the problem by using
Cmd.CombinedOutput()
instead ofcalling
Cmd.Start()
andCmd.Wait()
while reading from the output anderror pipes.
Details:
From the
exec
package documentation:In our tests, the old
execAndGetOutput
function was creating twogorutines to read from the stderr and stdout pipes of the command and
then call
Wait
on the command.This caused a race condition: when the
Wait
call finished before thegorutines have read from the pipes, they returned caused an error on
outErr
.The problem only happens sometimes on travis.
To reproduce the problem locally, just add a call to
time.Sleep(time.Second) to the gorutine before its
ioutil.ReadAll
callto delay them, then
Wait
will always finish before them, closing thepipes, and the gorutines will fail. The returned error detected by the
test will be: