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>2021-10-11 12:58:00 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-10-14 11:14:32 +0300
commit0fe1363e9f51e1d123e088a05e6b4b137c6b4f85 (patch)
treee9886a8d2917167dba8fc50da8f04c439b8aecfc /internal/praefect/info_service_test.go
parented2943d5a00cabb508f879bae167fe387ff87b6d (diff)
Use PerRepositoryRouter and Postgres in RepositoryReplicas tests
RepositoryReplicas tests currently use mocks instead of a real database and the actual production router. This commit updates the tests to use the production implementations.
Diffstat (limited to 'internal/praefect/info_service_test.go')
-rw-r--r--internal/praefect/info_service_test.go46
1 files changed, 37 insertions, 9 deletions
diff --git a/internal/praefect/info_service_test.go b/internal/praefect/info_service_test.go
index 36ea0f286..b026359fa 100644
--- a/internal/praefect/info_service_test.go
+++ b/internal/praefect/info_service_test.go
@@ -1,9 +1,9 @@
package praefect
import (
+ "math/rand"
"path/filepath"
"testing"
- "time"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
@@ -11,10 +11,11 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/repository"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/nodes"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/protoregistry"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
- "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/promtest"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
@@ -26,7 +27,8 @@ func TestInfoService_RepositoryReplicas(t *testing.T) {
var cfgs []gconfig.Cfg
var cfgNodes []*config.Node
var testRepo *gitalypb.Repository
- for i, storage := range []string{"g-1", "g-2", "g-3"} {
+ storages := []string{"g-1", "g-2", "g-3"}
+ for i, storage := range storages {
cfg, repo, _ := testcfg.BuildWithRepo(t, testcfg.WithStorages(storage))
if testRepo == nil {
testRepo = repo
@@ -50,8 +52,9 @@ func TestInfoService_RepositoryReplicas(t *testing.T) {
})
}
+ const virtualStorage = "default"
conf := config.Config{
- VirtualStorages: []*config.VirtualStorage{{Name: "default", Nodes: cfgNodes}},
+ VirtualStorages: []*config.VirtualStorage{{Name: virtualStorage, Nodes: cfgNodes}},
Failover: config.Failover{Enabled: true},
}
@@ -61,13 +64,38 @@ func TestInfoService_RepositoryReplicas(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- nodeManager, err := nodes.NewManager(testhelper.DiscardTestEntry(t), conf, nil, nil, promtest.NewMockHistogramVec(), protoregistry.GitalyProtoPreregistered, nil, nil, nil)
+ tx := glsql.NewDB(t).Begin(t)
+ defer tx.Rollback(t)
+
+ testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{
+ "praefect-0": map[string][]string{virtualStorage: storages},
+ })
+
+ nodeSet, err := DialNodes(ctx, conf.VirtualStorages, protoregistry.GitalyProtoPreregistered, nil, nil, nil)
require.NoError(t, err)
- nodeManager.Start(0, time.Hour)
- defer nodeManager.Stop()
+ defer nodeSet.Close()
+
+ elector := nodes.NewPerRepositoryElector(tx)
+ conns := nodeSet.Connections()
+ rs := datastore.NewPostgresRepositoryStore(tx, conf.StorageNames())
+ require.NoError(t,
+ rs.CreateRepository(ctx, 1, virtualStorage, testRepo.GetRelativePath(), "g-1", []string{"g-2", "g-3"}, nil, true, false),
+ )
+
cc, _, cleanup := runPraefectServer(t, ctx, conf, buildOptions{
- withPrimaryGetter: nodeManager,
- withConnections: NodeSetFromNodeManager(nodeManager).Connections(),
+ withConnections: conns,
+ withRepoStore: rs,
+ withRouter: NewPerRepositoryRouter(
+ conns,
+ elector,
+ StaticHealthChecker{virtualStorage: storages},
+ NewLockedRandom(rand.New(rand.NewSource(0))),
+ rs,
+ datastore.NewAssignmentStore(tx, conf.StorageNames()),
+ rs,
+ conf.DefaultReplicationFactors(),
+ ),
+ withPrimaryGetter: elector,
})
defer cleanup()