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-16 19:56:33 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-23 14:22:03 +0300
commit07acdf3940e27fd7727afd512b1681423ed587d1 (patch)
tree6fe8a27082ff01bfea621afddc2a2c6533d7d161
parent450056018f4337e293f8e0ff2d1731564e891f71 (diff)
Prepare object pool service's tests for replica path
Object pool service's test are working on the disk directly and they assume the object pool is stored at the relative path the client sent. This won't be the case anymore with Praefect rewriting relative paths to guarantee atomicity of creations, deletes and renames. This commit adjusts the tests to access the object pool at the path generated by Praefect if the tests are ran with Praefect in front.
-rw-r--r--internal/gitaly/service/objectpool/alternates_test.go4
-rw-r--r--internal/gitaly/service/objectpool/create_test.go5
-rw-r--r--internal/gitaly/service/objectpool/fetch_into_object_pool_test.go2
-rw-r--r--internal/gitaly/service/objectpool/link_test.go2
-rw-r--r--internal/gitaly/service/objectpool/testhelper_test.go31
5 files changed, 33 insertions, 11 deletions
diff --git a/internal/gitaly/service/objectpool/alternates_test.go b/internal/gitaly/service/objectpool/alternates_test.go
index 85ce42bbd..851dafb8e 100644
--- a/internal/gitaly/service/objectpool/alternates_test.go
+++ b/internal/gitaly/service/objectpool/alternates_test.go
@@ -82,7 +82,9 @@ func TestDisconnectGitAlternatesUnexpectedAlternates(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
repo := localrepo.NewTestRepo(t, cfg, repoProto)
altPath, err := repo.InfoAlternatesPath()
diff --git a/internal/gitaly/service/objectpool/create_test.go b/internal/gitaly/service/objectpool/create_test.go
index 63ae86ebf..f7dc13371 100644
--- a/internal/gitaly/service/objectpool/create_test.go
+++ b/internal/gitaly/service/objectpool/create_test.go
@@ -30,9 +30,8 @@ func TestCreate(t *testing.T) {
_, err := client.CreateObjectPool(ctx, poolReq)
require.NoError(t, err)
- defer func() {
- require.NoError(t, pool.Remove(ctx))
- }()
+
+ pool = rewrittenObjectPool(ctx, t, cfg, pool)
// Checks if the underlying repository is valid
require.True(t, pool.IsValid())
diff --git a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go
index a2583bd47..12e1376c3 100644
--- a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go
+++ b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go
@@ -49,6 +49,8 @@ func TestFetchIntoObjectPool_Success(t *testing.T) {
_, err = client.FetchIntoObjectPool(ctx, req)
require.NoError(t, err)
+ pool = rewrittenObjectPool(ctx, t, cfg, pool)
+
require.True(t, pool.IsValid(), "ensure underlying repository is valid")
// No problems
diff --git a/internal/gitaly/service/objectpool/link_test.go b/internal/gitaly/service/objectpool/link_test.go
index a1a7fb154..49d9176a0 100644
--- a/internal/gitaly/service/objectpool/link_test.go
+++ b/internal/gitaly/service/objectpool/link_test.go
@@ -156,6 +156,8 @@ func TestLinkNoPool(t *testing.T) {
_, err = client.LinkRepositoryToObjectPool(ctx, request)
require.NoError(t, err)
+ pool = rewrittenObjectPool(ctx, t, cfg, pool)
+
poolRepoPath, err := locator.GetRepoPath(pool)
require.NoError(t, err)
diff --git a/internal/gitaly/service/objectpool/testhelper_test.go b/internal/gitaly/service/objectpool/testhelper_test.go
index b0e35f6e3..36b349132 100644
--- a/internal/gitaly/service/objectpool/testhelper_test.go
+++ b/internal/gitaly/service/objectpool/testhelper_test.go
@@ -79,14 +79,10 @@ func runObjectPoolServer(t *testing.T, cfg config.Cfg, locator storage.Locator,
}, append(opts, testserver.WithLocator(locator), testserver.WithLogger(logger))...)
}
-// initObjectPool creates a new empty object pool in the given storage.
-func initObjectPool(t testing.TB, cfg config.Cfg, storage config.Storage) *objectpool.ObjectPool {
- t.Helper()
-
- relativePath := gittest.NewObjectPoolName(t)
- gittest.InitRepoDir(t, storage.Path, relativePath)
+func newObjectPool(t testing.TB, cfg config.Cfg, storage, relativePath string) *objectpool.ObjectPool {
catfileCache := catfile.NewCache(cfg)
t.Cleanup(catfileCache.Stop)
+
txManager := transaction.NewManager(cfg, backchannel.NewRegistry())
pool, err := objectpool.NewObjectPool(
@@ -95,13 +91,34 @@ func initObjectPool(t testing.TB, cfg config.Cfg, storage config.Storage) *objec
catfileCache,
txManager,
housekeeping.NewManager(txManager),
- storage.Name,
+ storage,
relativePath,
)
require.NoError(t, err)
+ return pool
+}
+
+// initObjectPool creates a new empty object pool in the given storage.
+func initObjectPool(t testing.TB, cfg config.Cfg, storage config.Storage) *objectpool.ObjectPool {
+ t.Helper()
+
+ relativePath := gittest.NewObjectPoolName(t)
+ gittest.InitRepoDir(t, storage.Path, relativePath)
+ catfileCache := catfile.NewCache(cfg)
+ t.Cleanup(catfileCache.Stop)
+
+ pool := newObjectPool(t, cfg, storage.Name, relativePath)
+
poolPath := filepath.Join(storage.Path, relativePath)
t.Cleanup(func() { require.NoError(t, os.RemoveAll(poolPath)) })
return pool
}
+
+// rewrittenObjectPool returns a pool that is rewritten as if it was passed through Praefect. This should be used
+// to access the pool on the disk if the tests are running with Praefect in front of them.
+func rewrittenObjectPool(ctx context.Context, t testing.TB, cfg config.Cfg, pool *objectpool.ObjectPool) *objectpool.ObjectPool {
+ replicaPath := gittest.GetReplicaPath(ctx, t, cfg, pool)
+ return newObjectPool(t, cfg, pool.GetStorageName(), replicaPath)
+}