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-06-27 15:54:44 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-30 16:43:28 +0300
commitb489ad97db7fe2873cf96767fb765f3b0d60c3ca (patch)
treee75dd43927493004c4b0fe2989309d962c8e469e
parent712b2ff9b2e8c20726344b479f778c3cac29b45b (diff)
repository: Merge functions to set up repository service server
Both `runRepositoryServerWithConfig()` and `runRepositoryService()` do essentially the same and indeed have the same function signature. The only difference is that the former one will only return the address, while the latter one also returns a gRPC client. This is misleading though given the `WithConfig()` suffix, which seems to indicate that it can accept a configuration while other functions can't. Fix this confusion by removing the former function and converting all current callers to use `runRepositoryService()` instead. This also allows us to get rid of constructing the gRPC client in many cases.
-rw-r--r--internal/gitaly/service/repository/archive_test.go7
-rw-r--r--internal/gitaly/service/repository/create_repository_from_snapshot_test.go7
-rw-r--r--internal/gitaly/service/repository/create_repository_test.go2
-rw-r--r--internal/gitaly/service/repository/replicate_test.go17
-rw-r--r--internal/gitaly/service/repository/repository_test.go4
-rw-r--r--internal/gitaly/service/repository/size_test.go3
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go11
7 files changed, 17 insertions, 34 deletions
diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go
index cdb347617..3c07ef602 100644
--- a/internal/gitaly/service/repository/archive_test.go
+++ b/internal/gitaly/service/repository/archive_test.go
@@ -191,8 +191,7 @@ func TestGetArchive_includeLfsBlobs(t *testing.T) {
},
}))
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil)
- client := newRepositoryClient(t, cfg, serverSocketPath)
+ client, serverSocketPath := runRepositoryService(t, cfg, nil)
cfg.SocketPath = serverSocketPath
repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
@@ -488,11 +487,9 @@ func TestGetArchive_environment(t *testing.T) {
testcfg.BuildGitalyHooks(t, cfg)
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil, testserver.WithGitCommandFactory(gitCmdFactory))
+ client, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithGitCommandFactory(gitCmdFactory))
cfg.SocketPath = serverSocketPath
- client := newRepositoryClient(t, cfg, serverSocketPath)
-
repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
commitID := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"
diff --git a/internal/gitaly/service/repository/create_repository_from_snapshot_test.go b/internal/gitaly/service/repository/create_repository_from_snapshot_test.go
index 9c7ca3383..cf605fc39 100644
--- a/internal/gitaly/service/repository/create_repository_from_snapshot_test.go
+++ b/internal/gitaly/service/repository/create_repository_from_snapshot_test.go
@@ -70,8 +70,7 @@ func generateTarFile(t *testing.T, path string) ([]byte, []string) {
func createFromSnapshot(t *testing.T, ctx context.Context, req *gitalypb.CreateRepositoryFromSnapshotRequest, cfg config.Cfg) (*gitalypb.CreateRepositoryFromSnapshotResponse, error) {
t.Helper()
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil)
- client := newRepositoryClient(t, cfg, serverSocketPath)
+ client, _ := runRepositoryService(t, cfg, nil)
return client.CreateRepositoryFromSnapshot(ctx, req)
}
@@ -106,8 +105,8 @@ func TestCreateRepositoryFromSnapshot_success(t *testing.T) {
HttpHost: host,
}
- cfg.SocketPath = runRepositoryServerWithConfig(t, cfg, nil)
- client := newRepositoryClient(t, cfg, cfg.SocketPath)
+ client, socketPath := runRepositoryService(t, cfg, nil)
+ cfg.SocketPath = socketPath
rsp, err := client.CreateRepositoryFromSnapshot(ctx, req)
require.NoError(t, err)
diff --git a/internal/gitaly/service/repository/create_repository_test.go b/internal/gitaly/service/repository/create_repository_test.go
index a612285fb..61a75db3a 100644
--- a/internal/gitaly/service/repository/create_repository_test.go
+++ b/internal/gitaly/service/repository/create_repository_test.go
@@ -32,7 +32,7 @@ func TestCreateRepository_missingAuth(t *testing.T) {
cfg, repo, _ := testcfg.BuildWithRepo(t, testcfg.WithBase(config.Cfg{Auth: auth.Config{Token: "some"}}))
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil)
+ _, serverSocketPath := runRepositoryService(t, cfg, nil)
client := newRepositoryClient(t, config.Cfg{Auth: auth.Config{Token: ""}}, serverSocketPath)
_, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: repo})
diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go
index f4f4a7030..44521db8f 100644
--- a/internal/gitaly/service/repository/replicate_test.go
+++ b/internal/gitaly/service/repository/replicate_test.go
@@ -48,11 +48,9 @@ func TestReplicateRepository(t *testing.T) {
testcfg.BuildGitalyHooks(t, cfg)
testcfg.BuildGitalySSH(t, cfg)
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil, testserver.WithDisablePraefect())
+ client, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect())
cfg.SocketPath = serverSocketPath
- client := newRepositoryClient(t, cfg, serverSocketPath)
-
repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
// create a loose object to ensure snapshot replication is used
@@ -121,7 +119,7 @@ func TestReplicateRepositoryTransactional(t *testing.T) {
testcfg.BuildGitalyHooks(t, cfg)
testcfg.BuildGitalySSH(t, cfg)
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil, testserver.WithDisablePraefect())
+ _, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect())
cfg.SocketPath = serverSocketPath
sourceRepo, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
@@ -330,11 +328,9 @@ func TestReplicateRepository_BadRepository(t *testing.T) {
testcfg.BuildGitalyHooks(t, cfg)
testcfg.BuildGitalySSH(t, cfg)
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil, testserver.WithDisablePraefect())
+ client, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect())
cfg.SocketPath = serverSocketPath
- client := newRepositoryClient(t, cfg, serverSocketPath)
-
sourceRepo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
targetRepo, targetRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[1], gittest.CloneRepoOpts{
RelativePath: sourceRepo.RelativePath,
@@ -386,7 +382,8 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) {
// Our test setup does not allow for Praefects with multiple storages. We thus have to
// disable Praefect here.
- cfg.SocketPath = runRepositoryServerWithConfig(t, cfg, nil, testserver.WithDisablePraefect())
+ client, socketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect())
+ cfg.SocketPath = socketPath
targetRepo, _ := gittest.InitRepo(t, cfg, cfg.Storages[1])
@@ -405,9 +402,7 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) {
ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg))
- repoClient := newRepositoryClient(t, cfg, cfg.SocketPath)
-
- _, err = repoClient.ReplicateRepository(ctx, &gitalypb.ReplicateRepositoryRequest{
+ _, err = client.ReplicateRepository(ctx, &gitalypb.ReplicateRepositoryRequest{
Repository: targetRepo,
Source: sourceRepo,
})
diff --git a/internal/gitaly/service/repository/repository_test.go b/internal/gitaly/service/repository/repository_test.go
index f5a26f61e..a834f19dc 100644
--- a/internal/gitaly/service/repository/repository_test.go
+++ b/internal/gitaly/service/repository/repository_test.go
@@ -21,12 +21,10 @@ func TestRepositoryExists(t *testing.T) {
require.NoError(t, os.RemoveAll(cfg.Storages[2].Path), "third storage needs to be invalid")
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil, testserver.WithDisablePraefect())
+ client, _ := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect())
repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- client := newRepositoryClient(t, cfg, serverSocketPath)
-
queries := []struct {
desc string
request *gitalypb.RepositoryExistsRequest
diff --git a/internal/gitaly/service/repository/size_test.go b/internal/gitaly/service/repository/size_test.go
index 2ce51466e..be9459f2f 100644
--- a/internal/gitaly/service/repository/size_test.go
+++ b/internal/gitaly/service/repository/size_test.go
@@ -37,10 +37,9 @@ func TestRepositorySize_SuccessfulRequest(t *testing.T) {
func testSuccessfulRepositorySizeRequestPoolMember(t *testing.T, ctx context.Context) {
cfg := testcfg.Build(t)
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, nil)
+ repoClient, serverSocketPath := runRepositoryService(t, cfg, nil)
cfg.SocketPath = serverSocketPath
- repoClient := newRepositoryClient(t, cfg, serverSocketPath)
objectPoolClient := newObjectPoolClient(t, cfg, serverSocketPath)
repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 5024918ca..c088de151 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -110,8 +110,8 @@ func assertModTimeAfter(t *testing.T, afterTime time.Time, paths ...string) bool
return t.Failed()
}
-func runRepositoryServerWithConfig(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Server, opts ...testserver.GitalyServerOpt) string {
- return testserver.RunGitalyServer(t, cfg, rubySrv, func(srv *grpc.Server, deps *service.Dependencies) {
+func runRepositoryService(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Server, opts ...testserver.GitalyServerOpt) (gitalypb.RepositoryServiceClient, string) {
+ serverSocketPath := testserver.RunGitalyServer(t, cfg, rubySrv, func(srv *grpc.Server, deps *service.Dependencies) {
gitalypb.RegisterRepositoryServiceServer(srv, NewServer(
cfg,
deps.GetRubyServer(),
@@ -156,13 +156,8 @@ func runRepositoryServerWithConfig(t testing.TB, cfg config.Cfg, rubySrv *rubyse
deps.GetHousekeepingManager(),
))
}, opts...)
-}
-
-func runRepositoryService(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Server, opts ...testserver.GitalyServerOpt) (gitalypb.RepositoryServiceClient, string) {
- serverSocketPath := runRepositoryServerWithConfig(t, cfg, rubySrv, opts...)
- client := newRepositoryClient(t, cfg, serverSocketPath)
- return client, serverSocketPath
+ return newRepositoryClient(t, cfg, serverSocketPath), serverSocketPath
}
func setupRepositoryService(ctx context.Context, t testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) {