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:
authorJohn Cai <jcai@gitlab.com>2019-12-10 04:15:07 +0300
committerJohn Cai <jcai@gitlab.com>2020-03-02 20:09:27 +0300
commit7e3381ec0d27059f0fb4e543c5ff10a80831fb4b (patch)
tree3c7b4acb80bafeb22b45cca1416b0ad11305fd08 /internal/praefect/info_service_test.go
parent0f65bca8b7b172afa1c22e31a74c1e1d8480025d (diff)
Change ListRepositories RPC to RepositoryReplicas
Instead of having an RPC return all repositories and their checksums, have an RPC that takes a repository as its argument and returns checksums of the primary and replicas.
Diffstat (limited to 'internal/praefect/info_service_test.go')
-rw-r--r--internal/praefect/info_service_test.go109
1 files changed, 109 insertions, 0 deletions
diff --git a/internal/praefect/info_service_test.go b/internal/praefect/info_service_test.go
new file mode 100644
index 000000000..b35769bd4
--- /dev/null
+++ b/internal/praefect/info_service_test.go
@@ -0,0 +1,109 @@
+package praefect
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ gconfig "gitlab.com/gitlab-org/gitaly/internal/config"
+ "gitlab.com/gitlab-org/gitaly/internal/praefect/config"
+ "gitlab.com/gitlab-org/gitaly/internal/praefect/models"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+)
+
+func TestInfoService_RepositoryReplicas(t *testing.T) {
+ conf := config.Config{
+ VirtualStorages: []*config.VirtualStorage{
+ {
+ Name: "default",
+ Nodes: []*models.Node{
+ {
+ Storage: "praefect-internal-1",
+ DefaultPrimary: true,
+ },
+ {
+ Storage: "praefect-internal-2",
+ },
+ {
+ Storage: "praefect-internal-3",
+ },
+ },
+ },
+ },
+ }
+
+ testRepo, _, cleanup := testhelper.NewTestRepo(t)
+ defer cleanup()
+
+ cc, _, cleanup := runPraefectServerWithGitaly(t, conf)
+ defer cleanup()
+
+ defer func(storages []gconfig.Storage) {
+ gconfig.Config.Storages = storages
+ }(gconfig.Config.Storages)
+
+ tempDir, cleanupTempDir := testhelper.TempDir(t, "praefect-test")
+ defer cleanupTempDir()
+
+ for _, node := range conf.VirtualStorages[0].Nodes {
+ storagePath := filepath.Join(tempDir, node.Storage)
+ require.NoError(t, os.MkdirAll(storagePath, 0755))
+ gconfig.Config.Storages = append(gconfig.Config.Storages, gconfig.Storage{
+ Name: node.Storage,
+ Path: storagePath,
+ })
+ }
+
+ testRepoPrimary, _, cleanup := cloneRepoAtStorage(t, testRepo, conf.VirtualStorages[0].Nodes[0].Storage)
+ defer cleanup()
+
+ _, _, cleanup = cloneRepoAtStorage(t, testRepo, conf.VirtualStorages[0].Nodes[1].Storage)
+ defer cleanup()
+ _, testRepoSecondary2Path, cleanup := cloneRepoAtStorage(t, testRepo, conf.VirtualStorages[0].Nodes[2].Storage)
+ defer cleanup()
+
+ // create a commit in the second replica so we can check that its checksum is different than the primary
+ testhelper.CreateCommit(t, testRepoSecondary2Path, "master", nil)
+
+ client := gitalypb.NewPraefectInfoServiceClient(cc)
+
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ // CalculateChecksum through praefect will get the checksum of the primary
+ repoClient := gitalypb.NewRepositoryServiceClient(cc)
+ checksum, err := repoClient.CalculateChecksum(ctx, &gitalypb.CalculateChecksumRequest{
+ Repository: &gitalypb.Repository{
+ StorageName: conf.VirtualStorages[0].Name,
+ RelativePath: testRepoPrimary.GetRelativePath(),
+ },
+ })
+ require.NoError(t, err)
+
+ resp, err := client.RepositoryReplicas(ctx, &gitalypb.RepositoryReplicasRequest{
+ Repository: &gitalypb.Repository{
+ StorageName: conf.VirtualStorages[0].Name,
+ RelativePath: testRepoPrimary.GetRelativePath(),
+ },
+ })
+
+ require.NoError(t, err)
+
+ require.Equal(t, checksum.Checksum, resp.Primary.Checksum)
+ var checked []string
+ for _, secondary := range resp.GetReplicas() {
+ switch storage := secondary.GetRepository().GetStorageName(); storage {
+ case conf.VirtualStorages[0].Nodes[1].Storage:
+ require.Equal(t, checksum.Checksum, secondary.Checksum)
+ checked = append(checked, storage)
+ case conf.VirtualStorages[0].Nodes[2].Storage:
+ require.NotEqual(t, checksum.Checksum, secondary.Checksum, "should not be equal since we added a commit")
+ checked = append(checked, storage)
+ default:
+ require.FailNow(t, "unexpected storage: %q", storage)
+ }
+ }
+ require.ElementsMatch(t, []string{conf.VirtualStorages[0].Nodes[1].Storage, conf.VirtualStorages[0].Nodes[2].Storage}, checked)
+}