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>2022-03-01 11:27:32 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-01 11:27:54 +0300
commitdb1b666501b1d618d0e0fe260423cd7d21e705ee (patch)
tree93dd1b4f7095dd91fd3014c974d2418bb8b6dbc8
parent29e11b58a847bcf87055cea2f30afd7a9c2accb4 (diff)
localrepo: Add test to demonstrate failure to unlock symrefs
We have recently added transactional support for writing symbolic references in a repository via the `safe.LockingFileWriter` interface. We forgot to unlock the writer in all cases though, which means that in some error conditions we may leave behind a lockfile. Add a testcase which demonstrates this failure to unlock.
-rw-r--r--internal/git/localrepo/refs_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/git/localrepo/refs_test.go b/internal/git/localrepo/refs_test.go
index 65fce6f20..6bbdea77a 100644
--- a/internal/git/localrepo/refs_test.go
+++ b/internal/git/localrepo/refs_test.go
@@ -3,6 +3,7 @@ package localrepo
import (
"bytes"
"context"
+ "errors"
"fmt"
"os"
"path/filepath"
@@ -598,6 +599,31 @@ func TestRepo_SetDefaultBranch_errors(t *testing.T) {
ch <- struct{}{}
<-doneCh
})
+
+ t.Run("failing vote unlocks symref", func(t *testing.T) {
+ ctx, err := txinfo.InjectTransaction(
+ peer.NewContext(ctx, &peer.Peer{}),
+ 1,
+ "node",
+ true,
+ )
+ require.NoError(t, err)
+
+ _, repo, repoPath := setupRepo(t)
+
+ failingTxManager := &transaction.MockManager{
+ VoteFn: func(context.Context, txinfo.Transaction, voting.Vote, voting.Phase) error {
+ return errors.New("injected error")
+ },
+ }
+
+ err = repo.SetDefaultBranch(ctx, failingTxManager, "refs/heads/branch")
+ require.Error(t, err)
+ require.Equal(t, "committing temporary HEAD: voting on locked file: preimage vote: injected error", err.Error())
+
+ // This is a bug: the lockfile does not get cleaned up correctly.
+ require.FileExists(t, filepath.Join(repoPath, "HEAD.lock"))
+ })
}
func TestGuessHead(t *testing.T) {