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:
authorKarthik Nayak <knayak@gitlab.com>2022-12-20 20:03:31 +0300
committerKarthik Nayak <knayak@gitlab.com>2022-12-22 13:08:58 +0300
commit4efabb9e7bcb3a3c13a9a17a7ec5044af9cc85fd (patch)
tree94440b3e9529394b48475db45b4665b8dcf1a392
parentb12948950d829e075dfafb6103bab6c114f2121e (diff)
repository: Add test for non-quarantined `FetchSourceBranch`
Currently `FetchSourceBranch` doesn't use a quarantined repository. Because of this, if there is a failure mid-way and refs are already pulled, we don't discard these refs. The fix for this is to move to using a quarantined repository. But before we do that, let's add a test to verify this behavior. When we do eventually fix this with quarantined repositories, this test would fail (test-driven development).
-rw-r--r--internal/gitaly/service/repository/fetch_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go
index d6acb6763..0091da3b9 100644
--- a/internal/gitaly/service/repository/fetch_test.go
+++ b/internal/gitaly/service/repository/fetch_test.go
@@ -3,14 +3,18 @@
package repository
import (
+ "fmt"
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/structerr"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -361,6 +365,54 @@ func TestFetchSourceBranch(t *testing.T) {
},
expectedErr: structerr.NewInvalidArgument("revision can't contain NUL"),
},
+ {
+ desc: "failure during/after fetch doesn't clean out fetched objects",
+ setup: func(t *testing.T) setupData {
+ cfg := testcfg.Build(t)
+
+ testcfg.BuildGitalyHooks(t, cfg)
+ testcfg.BuildGitalySSH(t, cfg)
+
+ // We simulate a failed fetch where we actually fetch but just exit
+ // with status 1, this will actually fetch the refs but gitaly will think
+ // git failed.
+ gitCmdFactory := gittest.NewInterceptingCommandFactory(t, ctx, cfg, func(execEnv git.ExecutionEnvironment) string {
+ return fmt.Sprintf(`#!/bin/bash
+ if [[ "$@" =~ "fetch" ]]; then
+ %q "$@"
+ exit 1
+ fi
+ exec %q "$@"`, execEnv.BinaryPath, execEnv.BinaryPath)
+ })
+
+ client, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithGitCommandFactory(gitCmdFactory))
+ cfg.SocketPath = serverSocketPath
+
+ sourceRepoProto, sourceRepoPath := gittest.CreateRepository(t, ctx, cfg)
+ commitID := gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master"))
+ repoProto, _ := gittest.CreateRepository(t, ctx, cfg)
+
+ return setupData{
+ cfg: cfg,
+ client: client,
+ request: &gitalypb.FetchSourceBranchRequest{
+ Repository: repoProto,
+ SourceRepository: sourceRepoProto,
+ SourceBranch: []byte("master"),
+ TargetRef: []byte("refs/tmp/fetch-source-branch-test"),
+ },
+ verify: func() {
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
+ exists, err := repo.HasRevision(ctx, commitID.Revision()+"^{commit}")
+ require.NoError(t, err)
+ // TODO: This should be fixed in:
+ // https://gitlab.com/gitlab-org/gitaly/-/issues/4520
+ require.True(t, exists, "fetched commit isn't discarded")
+ },
+ }
+ },
+ expectedResponse: &gitalypb.FetchSourceBranchResponse{Result: false},
+ },
} {
tc := tc