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:
authorSami Hiltunen <shiltunen@gitlab.com>2022-02-01 13:41:46 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-01 13:41:46 +0300
commit3fa7b15a34c2e0aeca64168f733e74f0c901a21f (patch)
tree3a29850a076222519c329a1cb26f54d77b542beb
parentf96abe4fe7ee74b83e96066a35316ce65cccfb8b (diff)
parent091c096494be91d671c9c8379c2672d0358b6246 (diff)
Merge branch 'smh-create-repo' into 'master'
Disable metadata creation hack in operation service tests See merge request gitlab-org/gitaly!4272
-rw-r--r--internal/git/gittest/repo.go91
-rw-r--r--internal/gitaly/service/operations/apply_patch_test.go14
-rw-r--r--internal/gitaly/service/operations/cherry_pick_test.go4
-rw-r--r--internal/gitaly/service/operations/commit_files_test.go38
-rw-r--r--internal/gitaly/service/operations/rebase_test.go39
-rw-r--r--internal/gitaly/service/operations/revert_test.go6
-rw-r--r--internal/gitaly/service/operations/squash_test.go7
-rw-r--r--internal/gitaly/service/operations/submodules_test.go2
-rw-r--r--internal/gitaly/service/operations/tags_test.go3
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go8
-rw-r--r--internal/gitaly/service/operations/update_branches_test.go4
-rw-r--r--internal/testhelper/testhelper.go8
-rw-r--r--internal/testhelper/testserver/gitaly.go63
13 files changed, 205 insertions, 82 deletions
diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go
index 26058d503..8ddd8e217 100644
--- a/internal/git/gittest/repo.go
+++ b/internal/git/gittest/repo.go
@@ -2,6 +2,7 @@ package gittest
import (
"bytes"
+ "context"
"crypto/sha256"
"os"
"path/filepath"
@@ -10,11 +11,16 @@ import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
+ gitalyauth "gitlab.com/gitlab-org/gitaly/v14/auth"
+ "gitlab.com/gitlab-org/gitaly/v14/client"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
)
const (
@@ -24,6 +30,9 @@ const (
// GlProjectPath is the default project path for newly created test
// repos.
GlProjectPath = "gitlab-org/gitlab-test"
+
+ // SeedGitLabTest is the path of the gitlab-test.git repository in _build/testrepos.
+ SeedGitLabTest = "gitlab-test.git"
)
// InitRepoDir creates a temporary directory for a repo, without initializing it
@@ -66,6 +75,88 @@ func newDiskHash(t testing.TB) string {
return filepath.Join(b[0:2], b[2:4], b)
}
+// CreateRepositoryConfig allows for configuring how the repository is created.
+type CreateRepositoryConfig struct {
+ // Storage determines the storage the repository is created in. If unset, the first storage
+ // from the config is used.
+ Storage config.Storage
+ // RelativePath sets the relative path of the repository in the storage. If unset,
+ // the relative path is set to a randomly generated hashed storage path
+ RelativePath string
+ // Seed determines which repository is used to seed the created repository. If unset, the repository
+ // is just created. The value should be one of the test repositories in _build/testrepos.
+ Seed string
+}
+
+// CreateRepository creates a new repository and returns it and its absolute path.
+func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs ...CreateRepositoryConfig) (*gitalypb.Repository, string) {
+ t.Helper()
+
+ require.Less(t, len(configs), 2, "you must either pass no or exactly one option")
+
+ opts := CreateRepositoryConfig{}
+ if len(configs) == 1 {
+ opts = configs[0]
+ }
+
+ dialOptions := []grpc.DialOption{}
+ if cfg.Auth.Token != "" {
+ dialOptions = append(dialOptions, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(cfg.Auth.Token)))
+ }
+
+ conn, err := client.DialContext(ctx, cfg.SocketPath, dialOptions)
+ require.NoError(t, err)
+ t.Cleanup(func() { conn.Close() })
+
+ storage := cfg.Storages[0]
+ if (opts.Storage != config.Storage{}) {
+ storage = opts.Storage
+ }
+
+ relativePath := newDiskHash(t)
+ if opts.RelativePath != "" {
+ relativePath = opts.RelativePath
+ }
+
+ repository := &gitalypb.Repository{
+ StorageName: storage.Name,
+ RelativePath: relativePath,
+ GlRepository: GlRepository,
+ GlProjectPath: GlProjectPath,
+ }
+
+ client := gitalypb.NewRepositoryServiceClient(conn)
+
+ if opts.Seed != "" {
+ _, err := client.CreateRepositoryFromURL(ctx, &gitalypb.CreateRepositoryFromURLRequest{
+ Repository: repository,
+ Url: testRepositoryPath(t, opts.Seed),
+ })
+ require.NoError(t, err)
+ } else {
+ _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{
+ Repository: repository,
+ })
+ require.NoError(t, err)
+ }
+
+ t.Cleanup(func() {
+ // The ctx parameter would be canceled by now as the tests defer the cancellation.
+ _, err := client.RemoveRepository(context.TODO(), &gitalypb.RemoveRepositoryRequest{
+ Repository: repository,
+ })
+
+ if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {
+ // The tests may delete the repository, so this is not a failure.
+ return
+ }
+
+ require.NoError(t, err)
+ })
+
+ return repository, filepath.Join(storage.Path, testhelper.GetReplicaPath(ctx, t, conn, repository))
+}
+
// InitRepoOpts contains options for InitRepo.
type InitRepoOpts struct {
// WithWorktree determines whether the resulting Git repository should have a worktree or
diff --git a/internal/gitaly/service/operations/apply_patch_test.go b/internal/gitaly/service/operations/apply_patch_test.go
index bd0939c30..5bf66a9fe 100644
--- a/internal/gitaly/service/operations/apply_patch_test.go
+++ b/internal/gitaly/service/operations/apply_patch_test.go
@@ -110,7 +110,13 @@ To restore the original branch and stop patching, run "git am --abort".
desc: "non-existent repository",
targetBranch: "master",
nonExistentRepository: true,
- error: status.Errorf(codes.NotFound, "GetRepoPath: not a git repository: \"%s/%s\"", cfg.Storages[0].Path, "doesnt-exist"),
+ error: func() error {
+ if testhelper.IsPraefectEnabled() {
+ return status.Errorf(codes.NotFound, "mutator call: route repository mutator: get repository id: repository %q/%q not found", cfg.Storages[0].Name, "doesnt-exist")
+ }
+
+ return status.Errorf(codes.NotFound, "GetRepoPath: not a git repository: \"%s/%s\"", cfg.Storages[0].Path, "doesnt-exist")
+ }(),
},
{
desc: "creating the first branch does not work",
@@ -269,7 +275,7 @@ To restore the original branch and stop patching, run "git am --abort".
},
} {
t.Run(tc.desc, func(t *testing.T) {
- repoPb, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoPb, repoPath := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoPb)
@@ -612,6 +618,10 @@ func TestUserApplyPatch_transactional(t *testing.T) {
ctx, _, repoProto, _, client := setupOperationsService(t, ctx, testserver.WithTransactionManager(txManager))
+ // Reset the transaction manager as the setup call above creates a repository which
+ // ends up creating some votes with Praefect enabled.
+ txManager.Reset()
+
ctx, err := txinfo.InjectTransaction(ctx, 1, "node", true)
require.NoError(t, err)
ctx = peer.NewContext(ctx, &peer.Peer{
diff --git a/internal/gitaly/service/operations/cherry_pick_test.go b/internal/gitaly/service/operations/cherry_pick_test.go
index 95108c753..deb3a0706 100644
--- a/internal/gitaly/service/operations/cherry_pick_test.go
+++ b/internal/gitaly/service/operations/cherry_pick_test.go
@@ -33,7 +33,9 @@ func TestServer_UserCherryPick_successful(t *testing.T) {
cherryPickedCommit, err := repo.ReadCommit(ctx, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
require.NoError(t, err)
- testRepoCopy, testRepoCopyPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) // read-only repo
+ testRepoCopy, testRepoCopyPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ }) // read-only repo
gittest.Exec(t, cfg, "-C", testRepoCopyPath, "branch", destinationBranch, "master")
diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go
index 3c5c54129..f6f1de640 100644
--- a/internal/gitaly/service/operations/commit_files_test.go
+++ b/internal/gitaly/service/operations/commit_files_test.go
@@ -4,10 +4,8 @@ import (
"context"
"encoding/base64"
"fmt"
- "os"
"path/filepath"
"strconv"
- "strings"
"testing"
"time"
@@ -40,15 +38,7 @@ func TestUserCommitFiles(t *testing.T) {
targetRelativePath = "target-repository"
)
- // Multiple locations in the call path depend on the global configuration.
- // This creates a clean directory in the test storage. We then recreate the
- // repository there on every test run. This allows us to use deterministic
- // paths in the tests.
-
- startRepo, startRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
-
- pathToStorage := strings.TrimSuffix(startRepoPath, startRepo.RelativePath)
- repoPath := filepath.Join(pathToStorage, targetRelativePath)
+ startRepo, _ := gittest.CreateRepository(ctx, t, cfg)
type step struct {
actions []*gitalypb.UserCommitFilesRequest
@@ -877,17 +867,11 @@ func TestUserCommitFiles(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- defer func() { require.NoError(t, os.RemoveAll(repoPath)) }()
- gittest.Exec(t, cfg, "init", "--bare", repoPath)
+ const branch = "main"
- const branch = "master"
-
- repo := &gitalypb.Repository{
- StorageName: startRepo.GetStorageName(),
- RelativePath: targetRelativePath,
- GlRepository: gittest.GlRepository,
- GlProjectPath: gittest.GlProjectPath,
- }
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ RelativePath: targetRelativePath,
+ })
for i, step := range tc.steps {
headerRequest := headerRequest(
@@ -943,7 +927,7 @@ func TestUserCommitFilesStableCommitID(t *testing.T) {
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
for key, values := range testcfg.GitalyServersMetadataFromCfg(t, cfg) {
@@ -1001,7 +985,7 @@ func TestUserCommitFilesQuarantine(t *testing.T) {
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg))
@@ -1044,7 +1028,7 @@ func TestSuccessfulUserCommitFilesRequest(t *testing.T) {
ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx)
- newRepo, newRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ newRepo, newRepoPath := gittest.CreateRepository(ctx, t, cfg)
filePath := "héllo/wörld"
authorName := []byte("Jane Doe")
@@ -1169,7 +1153,9 @@ func TestSuccessfulUserCommitFilesRequestMove(t *testing.T) {
{content: "foo", infer: true},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
origFileContent := gittest.Exec(t, cfg, "-C", testRepoPath, "show", branchName+":"+previousFilePath)
headerRequest := headerRequest(testRepo, gittest.TestUser, branchName, commitFilesMessage, "")
@@ -1341,7 +1327,7 @@ func TestSuccessfulUserCommitFilesRequestWithSpecialCharactersInSignature(t *tes
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
targetBranchName := "master"
diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go
index 1ac91dfe4..3574bda5b 100644
--- a/internal/gitaly/service/operations/rebase_test.go
+++ b/internal/gitaly/service/operations/rebase_test.go
@@ -3,6 +3,7 @@ package operations
import (
"fmt"
"io"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -36,7 +37,9 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branchSha := getBranchSha(t, cfg, repoPath, rebaseBranchName)
@@ -420,8 +423,9 @@ func TestAbortedUserRebaseConfirmable(t *testing.T) {
for i, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- testRepoCopy, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ createRepoOpts := gittest.CreateRepositoryConfig{Seed: gittest.SeedGitLabTest}
+ testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, createRepoOpts)
+ testRepoCopy, _ := gittest.CreateRepository(ctx, t, cfg, createRepoOpts)
branchSha := getBranchSha(t, cfg, testRepoPath, rebaseBranchName)
@@ -467,7 +471,9 @@ func TestFailedUserRebaseConfirmableDueToApplyBeingFalse(t *testing.T) {
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- testRepoCopy, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepoCopy, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branchSha := getBranchSha(t, cfg, repoPath, rebaseBranchName)
@@ -506,7 +512,9 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branchSha := getBranchSha(t, cfg, repoPath, rebaseBranchName)
@@ -559,7 +567,9 @@ func TestFailedUserRebaseConfirmableDueToGitError(t *testing.T) {
ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
failedBranchName := "rebase-encoding-failure-trigger"
branchSha := getBranchSha(t, cfg, repoPath, failedBranchName)
@@ -590,14 +600,15 @@ func TestRebaseRequestWithDeletedFile(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
- })
+ ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
+ gittest.AddWorktree(t, cfg, repoPath, "worktree")
+ repoPath = filepath.Join(repoPath, "worktree")
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- repoCopyProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoCopyProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
branch := "rebase-delete-test"
@@ -649,9 +660,11 @@ func TestRebaseOntoRemoteBranch(t *testing.T) {
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- remoteRepo, remoteRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
+ remoteRepo, remoteRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
})
+ gittest.AddWorktree(t, cfg, remoteRepoPath, "worktree")
+ remoteRepoPath = filepath.Join(remoteRepoPath, "worktree")
localBranch := "master"
localBranchHash := getBranchSha(t, cfg, repoPath, localBranch)
diff --git a/internal/gitaly/service/operations/revert_test.go b/internal/gitaly/service/operations/revert_test.go
index 685e8947d..0305d6534 100644
--- a/internal/gitaly/service/operations/revert_test.go
+++ b/internal/gitaly/service/operations/revert_test.go
@@ -33,7 +33,9 @@ func TestServer_UserRevert_successful(t *testing.T) {
revertedCommit, err := repo.ReadCommit(ctx, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
- testRepoCopy, testRepoCopyPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) // read-only repo
+ testRepoCopy, testRepoCopyPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ }) // read-only repo
gittest.Exec(t, cfg, "-C", testRepoCopyPath, "branch", destinationBranch, "master")
@@ -282,7 +284,7 @@ func TestServer_UserRevert_successfulIntoEmptyRepo(t *testing.T) {
masterHeadCommit, err := startRepo.ReadCommit(ctx, "master")
require.NoError(t, err)
- repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.CreateRepository(ctx, t, cfg)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
request := &gitalypb.UserRevertRequest{
diff --git a/internal/gitaly/service/operations/squash_test.go b/internal/gitaly/service/operations/squash_test.go
index ada77a9d3..b758ba4aa 100644
--- a/internal/gitaly/service/operations/squash_test.go
+++ b/internal/gitaly/service/operations/squash_test.go
@@ -207,11 +207,10 @@ func TestUserSquash_renames(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- ctx, cfg, _, _, client := setupOperationsService(t, ctx)
+ ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx)
- repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
- })
+ gittest.AddWorktree(t, cfg, repoPath, "worktree")
+ repoPath = filepath.Join(repoPath, "worktree")
repo := localrepo.NewTestRepo(t, cfg, repoProto)
diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go
index d45c0d2aa..6c6107b6c 100644
--- a/internal/gitaly/service/operations/submodules_test.go
+++ b/internal/gitaly/service/operations/submodules_test.go
@@ -372,7 +372,7 @@ func TestFailedUserUpdateSubmoduleRequestDueToRepositoryEmpty(t *testing.T) {
ctx, cfg, _, _, client := setupOperationsService(t, ctx)
- repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repo, _ := gittest.CreateRepository(ctx, t, cfg)
request := &gitalypb.UserUpdateSubmoduleRequest{
Repository: repo,
diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go
index ef9831fa5..9018e4345 100644
--- a/internal/gitaly/service/operations/tags_test.go
+++ b/internal/gitaly/service/operations/tags_test.go
@@ -43,8 +43,9 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
User: gittest.TestUser,
}
- _, err := client.UserDeleteTag(ctx, request)
+ response, err := client.UserDeleteTag(ctx, request)
require.NoError(t, err)
+ require.Empty(t, response.PreReceiveError)
tags := gittest.Exec(t, cfg, "-C", repoPath, "tag")
require.NotContains(t, string(tags), tagNameInput, "tag name still exists in tags list")
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index 990264428..625b39c86 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -44,8 +44,6 @@ func setupOperationsService(t testing.TB, ctx context.Context, options ...testse
func setupOperationsServiceWithCfg(
t testing.TB, ctx context.Context, cfg config.Cfg, options ...testserver.GitalyServerOpt,
) (context.Context, config.Cfg, *gitalypb.Repository, string, gitalypb.OperationServiceClient) {
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
-
testcfg.BuildGitalySSH(t, cfg)
testcfg.BuildGitalyGit2Go(t, cfg)
testcfg.BuildGitalyHooks(t, cfg)
@@ -59,12 +57,18 @@ func setupOperationsServiceWithCfg(
md := testcfg.GitalyServersMetadataFromCfg(t, cfg)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
+
return ctx, cfg, repo, repoPath, client
}
func runOperationServiceServer(t testing.TB, cfg config.Cfg, options ...testserver.GitalyServerOpt) string {
t.Helper()
+ options = append(options, testserver.WithDisableMetadataForceCreation())
+
return testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
operationServer := NewServer(
deps.GetHookManager(),
diff --git a/internal/gitaly/service/operations/update_branches_test.go b/internal/gitaly/service/operations/update_branches_test.go
index e069ce8f8..1ea5701fa 100644
--- a/internal/gitaly/service/operations/update_branches_test.go
+++ b/internal/gitaly/service/operations/update_branches_test.go
@@ -173,7 +173,9 @@ func TestSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T) {
for _, hookName := range GitlabHooks {
t.Run(hookName, func(t *testing.T) {
- testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
hookOutputTempPath := gittest.WriteEnvToCustomHook(t, testRepoPath, hookName)
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index a9ebfe62a..77e7bb6a7 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -63,10 +63,16 @@ func GetReplicaPath(ctx context.Context, t testing.TB, conn *grpc.ClientConn, re
return metadata.ReplicaPath
}
+// IsPraefectEnabled returns whether this testing run is done with Praefect in front of the Gitaly.
+func IsPraefectEnabled() bool {
+ _, enabled := os.LookupEnv("GITALY_TEST_WITH_PRAEFECT")
+ return enabled
+}
+
// SkipWithPraefect skips the test if it is being executed with Praefect in front
// of the Gitaly.
func SkipWithPraefect(t testing.TB, reason string) {
- if os.Getenv("GITALY_TEST_WITH_PRAEFECT") == "YesPlease" {
+ if IsPraefectEnabled() {
t.Skipf(reason)
}
}
diff --git a/internal/testhelper/testserver/gitaly.go b/internal/testhelper/testserver/gitaly.go
index 4658d57bd..5c84038be 100644
--- a/internal/testhelper/testserver/gitaly.go
+++ b/internal/testhelper/testserver/gitaly.go
@@ -48,16 +48,16 @@ func RunGitalyServer(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Server
// StartGitalyServer creates and runs gitaly (and praefect as a proxy) server.
func StartGitalyServer(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Server, registrar func(srv *grpc.Server, deps *service.Dependencies), opts ...GitalyServerOpt) GitalyServer {
- gitalySrv, gitalyAddr, disablePraefect := runGitaly(t, cfg, rubyServer, registrar, opts...)
+ gitalySrv, gitalyAddr, disablePraefect, disableMetadataForceCreation := runGitaly(t, cfg, rubyServer, registrar, opts...)
- if !isPraefectEnabled() || disablePraefect {
+ if !testhelper.IsPraefectEnabled() || disablePraefect {
return GitalyServer{
shutdown: gitalySrv.Stop,
address: gitalyAddr,
}
}
- praefectServer := runPraefectProxy(t, cfg, gitalyAddr)
+ praefectServer := runPraefectProxy(t, cfg, gitalyAddr, disableMetadataForceCreation)
return GitalyServer{
shutdown: func() {
praefectServer.Shutdown()
@@ -67,7 +67,7 @@ func StartGitalyServer(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Serv
}
}
-func runPraefectProxy(t testing.TB, gitalyCfg config.Cfg, gitalyAddr string) PraefectServer {
+func runPraefectProxy(t testing.TB, gitalyCfg config.Cfg, gitalyAddr string, disableMetadataForceCreation bool) PraefectServer {
return StartPraefect(t, praefectconfig.Config{
SocketPath: testhelper.GetTemporaryGitalySocketFileName(t),
Auth: auth.Config{
@@ -83,7 +83,7 @@ func runPraefectProxy(t testing.TB, gitalyCfg config.Cfg, gitalyAddr string) Pra
Format: "json",
Level: "panic",
},
- ForceCreateRepositories: true,
+ ForceCreateRepositories: !disableMetadataForceCreation,
VirtualStorages: []*praefectconfig.VirtualStorage{
{
// Only single storage will be served by the Praefect instance. We
@@ -142,7 +142,7 @@ func waitHealthy(t testing.TB, addr string, authToken string) {
require.Equal(t, healthpb.HealthCheckResponse_SERVING, resp.Status, "server not yet ready to serve")
}
-func runGitaly(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Server, registrar func(srv *grpc.Server, deps *service.Dependencies), opts ...GitalyServerOpt) (*grpc.Server, string, bool) {
+func runGitaly(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Server, registrar func(srv *grpc.Server, deps *service.Dependencies), opts ...GitalyServerOpt) (*grpc.Server, string, bool, bool) {
t.Helper()
var gsd gitalyServerDeps
@@ -214,7 +214,7 @@ func runGitaly(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Server, regi
waitHealthy(t, addr, cfg.Auth.Token)
- return externalServer, addr, gsd.disablePraefect
+ return externalServer, addr, gsd.disablePraefect, gsd.disableMetadataForceCreation
}
func registerHealthServerIfNotRegistered(srv *grpc.Server) {
@@ -226,22 +226,23 @@ func registerHealthServerIfNotRegistered(srv *grpc.Server) {
}
type gitalyServerDeps struct {
- disablePraefect bool
- logger *logrus.Logger
- conns *client.Pool
- locator storage.Locator
- txMgr transaction.Manager
- hookMgr hook.Manager
- gitlabClient gitlab.Client
- gitCmdFactory git.CommandFactory
- linguist *linguist.Instance
- backchannelReg *backchannel.Registry
- catfileCache catfile.Cache
- diskCache cache.Cache
- packObjectsCache streamcache.Cache
- limitHandler *limithandler.LimiterMiddleware
- git2goExecutor *git2go.Executor
- updaterWithHooks *updateref.UpdaterWithHooks
+ disablePraefect bool
+ disableMetadataForceCreation bool
+ logger *logrus.Logger
+ conns *client.Pool
+ locator storage.Locator
+ txMgr transaction.Manager
+ hookMgr hook.Manager
+ gitlabClient gitlab.Client
+ gitCmdFactory git.CommandFactory
+ linguist *linguist.Instance
+ backchannelReg *backchannel.Registry
+ catfileCache catfile.Cache
+ diskCache cache.Cache
+ packObjectsCache streamcache.Cache
+ limitHandler *limithandler.LimiterMiddleware
+ git2goExecutor *git2go.Executor
+ updaterWithHooks *updateref.UpdaterWithHooks
}
func (gsd *gitalyServerDeps) createDependencies(t testing.TB, cfg config.Cfg, rubyServer *rubyserver.Server) *service.Dependencies {
@@ -392,6 +393,17 @@ func WithDisablePraefect() GitalyServerOpt {
}
}
+// WithDisableMetadataForceCreation disables a testing hack to create repository metadata when Praefect first sees a request
+// for a repository. This can be used to ensure the test does not rely on the force creation behavior after it has been fixed
+// to not depend on it anymore. New tests should use this to avoid adding to the problem. This option can be removed once the hack
+// itself has been removed.
+func WithDisableMetadataForceCreation() GitalyServerOpt {
+ return func(deps gitalyServerDeps) gitalyServerDeps {
+ deps.disableMetadataForceCreation = true
+ return deps
+ }
+}
+
// WithBackchannelRegistry sets backchannel.Registry instance that will be used for gitaly services initialisation.
func WithBackchannelRegistry(backchannelReg *backchannel.Registry) GitalyServerOpt {
return func(deps gitalyServerDeps) gitalyServerDeps {
@@ -407,8 +419,3 @@ func WithDiskCache(diskCache cache.Cache) GitalyServerOpt {
return deps
}
}
-
-func isPraefectEnabled() bool {
- _, ok := os.LookupEnv("GITALY_TEST_WITH_PRAEFECT")
- return ok
-}