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-05-06 09:22:54 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-05-16 15:59:21 +0300
commitc6f599c80e397ea1fb4fc8a8f247fdd65709c50e (patch)
treed203678f3f67c793b4358e5e06ed1366f6b068cd
parent42fab8fc526215f9426bc9f459f9e6da0951c574 (diff)
Resolve replica path in background verifier tests
To test scenarios where the replica pointed to by a metadata record does not exist, the verifier deletes replicas from Gitalys as part of its test setup. It does so by pointing the calls to the relative path and does not resolve the replica path. This causes the tests to fail when Praefect generates unique replica paths. This commit resolves the replica path in the tests so the deletions always target the correct repositories. As the helpers are mostly designed with Gitaly in mind, the GetReplicaPath helper currently expects a Gitaly config which it will use to dial the service. In Praefect's context, we don't have such a config available nor do we even have the address of the server. This commit expands the helper to take a ClientConn in to use optionally as the other helpers do.
-rw-r--r--internal/git/gittest/repo.go23
-rw-r--r--internal/praefect/verifier_test.go6
2 files changed, 24 insertions, 5 deletions
diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go
index 020ae8271..88c8f93d4 100644
--- a/internal/git/gittest/repo.go
+++ b/internal/git/gittest/repo.go
@@ -178,13 +178,30 @@ func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs
return clonedRepo, filepath.Join(storage.Path, getReplicaPath(ctx, t, conn, repository))
}
+// GetReplicaPathConfig allows for configuring the GetReplicaPath call.
+type GetReplicaPathConfig struct {
+ // ClientConn is the connection used to create the repository. If unset, the config is used to
+ // dial the service.
+ ClientConn *grpc.ClientConn
+}
+
// GetReplicaPath retrieves the repository's replica path if the test has been
// run with Praefect in front of it. This is necessary if the test creates a repository
// through Praefect and peeks into the filesystem afterwards. Conn should be pointing to
// Praefect.
-func GetReplicaPath(ctx context.Context, t testing.TB, cfg config.Cfg, repo repository.GitRepo) string {
- conn := dialService(ctx, t, cfg)
- defer conn.Close()
+func GetReplicaPath(ctx context.Context, t testing.TB, cfg config.Cfg, repo repository.GitRepo, opts ...GetReplicaPathConfig) string {
+ require.Less(t, len(opts), 2, "you must either pass no or exactly one option")
+
+ var opt GetReplicaPathConfig
+ if len(opts) > 0 {
+ opt = opts[0]
+ }
+
+ conn := opt.ClientConn
+ if conn == nil {
+ conn = dialService(ctx, t, cfg)
+ defer conn.Close()
+ }
return getReplicaPath(ctx, t, conn, repo)
}
diff --git a/internal/praefect/verifier_test.go b/internal/praefect/verifier_test.go
index 674089166..33441ff07 100644
--- a/internal/praefect/verifier_test.go
+++ b/internal/praefect/verifier_test.go
@@ -546,11 +546,13 @@ func TestVerifier(t *testing.T) {
for virtualStorage, relativePaths := range tc.replicas {
for relativePath, storages := range relativePaths {
// Create the expected repository. This creates all of the replicas transactionally.
- gittest.CreateRepository(ctx, t,
+ repo, _ := gittest.CreateRepository(ctx, t,
gitalyconfig.Cfg{Storages: []gitalyconfig.Storage{{Name: virtualStorage}}},
gittest.CreateRepositoryConfig{ClientConn: conn, RelativePath: relativePath},
)
+ replicaPath := gittest.GetReplicaPath(ctx, t, gitalyconfig.Cfg{}, repo, gittest.GetReplicaPathConfig{ClientConn: conn})
+
// Now remove the replicas that were created in the transaction but the test case
// expects not to exist. We remove them directly from the Gitalys so the metadata
// records are left in place.
@@ -591,7 +593,7 @@ func TestVerifier(t *testing.T) {
&gitalypb.RemoveRepositoryRequest{
Repository: &gitalypb.Repository{
StorageName: storage,
- RelativePath: relativePath,
+ RelativePath: replicaPath,
},
},
)