diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-20 11:14:32 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-26 17:01:45 +0300 |
commit | 995cd3db9810219b1e45305b3f449f568006e7ba (patch) | |
tree | 84004f8073c17b25a88d2662f442964bf59cb4f1 | |
parent | ed90d91fa0ae2108b7a3174e1f890fd72749e922 (diff) |
testhelper: Move `SetHealthyNodes()` into new `testdb` package
Move the `SetHealthyNodes()` helper function into a new `testdb` package
to break a cyclic dependency between the testhelper package and the
`internal/gitaly/config` package.
-rw-r--r-- | cmd/praefect/subcmd_dataloss_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/coordinator_pg_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/coordinator_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/datastore/collector_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/datastore/repository_store_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/info_service_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/nodes/per_repository_test.go | 3 | ||||
-rw-r--r-- | internal/praefect/router_per_repository_test.go | 5 | ||||
-rw-r--r-- | internal/praefect/server_test.go | 3 | ||||
-rw-r--r-- | internal/testhelper/testdb/db.go (renamed from internal/testhelper/db.go) | 2 |
10 files changed, 20 insertions, 11 deletions
diff --git a/cmd/praefect/subcmd_dataloss_test.go b/cmd/praefect/subcmd_dataloss_test.go index 07d7ad602..073731f97 100644 --- a/cmd/praefect/subcmd_dataloss_test.go +++ b/cmd/praefect/subcmd_dataloss_test.go @@ -10,6 +10,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/info" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc" ) @@ -47,7 +48,7 @@ func TestDatalossSubcommand(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect-0": { + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect-0": { "virtual-storage-1": {"gitaly-1", "gitaly-3"}, }}) gs := datastore.NewPostgresRepositoryStore(tx, cfg.StorageNames()) diff --git a/internal/praefect/coordinator_pg_test.go b/internal/praefect/coordinator_pg_test.go index 20c447ee7..fbcdf048c 100644 --- a/internal/praefect/coordinator_pg_test.go +++ b/internal/praefect/coordinator_pg_test.go @@ -17,6 +17,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/transactions" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" @@ -213,7 +214,7 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) { require.NoError(t, rs.SetGeneration(ctx, 1, storageNodes[i].Storage, n.generation)) } - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": conf.StorageNames()}) + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": conf.StorageNames()}) nodeSet, err := DialNodes( ctx, diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go index b9e4230d2..6abfd8c7b 100644 --- a/internal/praefect/coordinator_test.go +++ b/internal/praefect/coordinator_test.go @@ -38,6 +38,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/promtest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/voting" @@ -197,7 +198,7 @@ func TestStreamDirectorMutator(t *testing.T) { require.NoError(t, rs.CreateRepository(ctx, 1, targetRepo.StorageName, targetRepo.RelativePath, primaryNode.Storage, []string{secondaryNode.Storage}, nil, true, true)) } - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": conf.StorageNames()}) + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": conf.StorageNames()}) queueInterceptor := datastore.NewReplicationEventQueueInterceptor(datastore.NewPostgresReplicationEventQueue(db)) queueInterceptor.OnEnqueue(func(ctx context.Context, event datastore.ReplicationEvent, queue datastore.ReplicationEventQueue) (datastore.ReplicationEvent, error) { assert.True(t, len(queueInterceptor.GetEnqueued()) < 2, "expected only one event to be created") diff --git a/internal/praefect/datastore/collector_test.go b/internal/praefect/datastore/collector_test.go index d2a03de01..aacb20b82 100644 --- a/internal/praefect/datastore/collector_test.go +++ b/internal/praefect/datastore/collector_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" ) func TestRepositoryStoreCollector(t *testing.T) { @@ -151,7 +152,7 @@ func TestRepositoryStoreCollector(t *testing.T) { tx := db.Begin(t) defer tx.Rollback(t) - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{ + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{ "praefect-0": {"virtual-storage-1": tc.healthyNodes}, }) diff --git a/internal/praefect/datastore/repository_store_test.go b/internal/praefect/datastore/repository_store_test.go index a004ba88d..920e02e5f 100644 --- a/internal/praefect/datastore/repository_store_test.go +++ b/internal/praefect/datastore/repository_store_test.go @@ -12,6 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/commonerr" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" ) // repositoryRecord represents Praefect's records related to a repository. @@ -1307,7 +1308,7 @@ func TestPostgresRepositoryStore_GetPartiallyAvailableRepositories(t *testing.T) healthyStorages = append(healthyStorages, storage) } - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{ + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{ "praefect-0": {"virtual-storage": healthyStorages}, }) diff --git a/internal/praefect/info_service_test.go b/internal/praefect/info_service_test.go index a49284124..96f86ab64 100644 --- a/internal/praefect/info_service_test.go +++ b/internal/praefect/info_service_test.go @@ -17,6 +17,7 @@ import ( "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/testcfg" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc" @@ -67,7 +68,7 @@ func TestInfoService_RepositoryReplicas(t *testing.T) { tx := glsql.NewDB(t).Begin(t) defer tx.Rollback(t) - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{ + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{ "praefect-0": {virtualStorage: storages}, }) diff --git a/internal/praefect/nodes/per_repository_test.go b/internal/praefect/nodes/per_repository_test.go index 27d69609b..028f8b7e8 100644 --- a/internal/praefect/nodes/per_repository_test.go +++ b/internal/praefect/nodes/per_repository_test.go @@ -11,6 +11,7 @@ import ( "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/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" ) func TestPerRepositoryElector(t *testing.T) { @@ -532,7 +533,7 @@ func TestPerRepositoryElector(t *testing.T) { for _, step := range tc.steps { runElection := func(tx *glsql.TxWrapper) (string, *logrus.Entry) { - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect-0": step.healthyNodes}) + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect-0": step.healthyNodes}) logger, hook := test.NewNullLogger() elector := NewPerRepositoryElector(tx) diff --git a/internal/praefect/router_per_repository_test.go b/internal/praefect/router_per_repository_test.go index 9eab31307..8863e579a 100644 --- a/internal/praefect/router_per_repository_test.go +++ b/internal/praefect/router_per_repository_test.go @@ -12,6 +12,7 @@ import ( "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/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -215,7 +216,7 @@ func TestPerRepositoryRouter_RouteRepositoryAccessor(t *testing.T) { tx := db.Begin(t) defer tx.Rollback(t) - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": { + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": { "virtual-storage-1": {"primary", "consistent-secondary", "inconsistent-secondary"}, }}) @@ -365,7 +366,7 @@ func TestPerRepositoryRouter_RouteRepositoryMutator(t *testing.T) { tx := db.Begin(t) defer tx.Rollback(t) - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": configuredNodes}) + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": configuredNodes}) const relativePath = "repository" diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go index c635b811f..c9a9fb25d 100644 --- a/internal/praefect/server_test.go +++ b/internal/praefect/server_test.go @@ -43,6 +43,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/promtest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/voting" @@ -645,7 +646,7 @@ func TestRenameRepository(t *testing.T) { require.NoError(t, err) defer nodeSet.Close() - testhelper.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": praefectCfg.StorageNames()}) + testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{"praefect": praefectCfg.StorageNames()}) cc, _, cleanup := runPraefectServer(t, ctx, praefectCfg, buildOptions{ withQueue: evq, diff --git a/internal/testhelper/db.go b/internal/testhelper/testdb/db.go index 130e39950..73c5d39f8 100644 --- a/internal/testhelper/db.go +++ b/internal/testhelper/testdb/db.go @@ -1,4 +1,4 @@ -package testhelper +package testdb import ( "context" |