Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-09-21 14:42:45 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-09-21 14:47:26 +0300
commit88b946a0de28da1b643c7a90505182858e73facf (patch)
treeb0df709f2bd8194ec515d1abd2960a87e3ff27e9
parent10a77e97a1392ecb76eb6148d1ce45f3d5b87cbd (diff)
updateref: Fix test flakiness when writing to updater fails
In one of our tests for the updateref package, we verify that we get an error when trying to commit a change on a transaction that has already been prepared. The test is flaky though given that it sometimes does not return the expected error message from git-update-ref(1). This race is caused by git-update-ref(1) exiting before we get to the point where we can write another status change command to its stdin, and as a result we get a failure writing to the command's pipe instead of the expected error. Fix this bug by explicitly cancelling the command and including its stderr when writing to it fails. This makes sure that stderr was flushed and we've got it available, and it would also include the error message we are searching for in the test.
-rw-r--r--internal/git/updateref/updateref.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go
index dde7b5b76..630c3ebb3 100644
--- a/internal/git/updateref/updateref.go
+++ b/internal/git/updateref/updateref.go
@@ -153,7 +153,10 @@ func (u *Updater) Cancel() error {
func (u *Updater) setState(state string) error {
_, err := fmt.Fprintf(u.cmd, "%s\x00", state)
if err != nil {
- return fmt.Errorf("updating state to %q: %w", state, err)
+ // We need to explicitly cancel the command here and wait for it to terminate such
+ // that we can retrieve the command's stderr in a race-free manner.
+ _ = u.Cancel()
+ return fmt.Errorf("updating state to %q: %w, stderr: %q", state, err, u.stderr)
}
// For each state-changing command, git-update-ref(1) will report successful execution via