diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2020-12-01 13:40:32 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2020-12-02 18:37:03 +0300 |
commit | b24283b141c8a25b14b312fbb7413842b7bd2a3f (patch) | |
tree | 9506e42cc586696be9161aa513727721ab283d71 /internal/praefect/replicator_test.go | |
parent | 0204129bc3ca6d2c2a33b8f5f63f3c3336f91de5 (diff) |
use postgres repository store in TestReplicatorInvalidSourceRepository
Uses Postgres repository store in TestReplicatorInvalidSourceRepository
in preparation of MemoryRepositoryStore's removal. The test asserts the
repository is properly deleted which makes it test the integration of
between the RepositoryStore and the replicator.
test invalid source repository test
Diffstat (limited to 'internal/praefect/replicator_test.go')
-rw-r--r-- | internal/praefect/replicator_test.go | 53 |
1 files changed, 3 insertions, 50 deletions
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index c186eb74f..52a1b7b48 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -31,6 +31,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/middleware/metadatahandler" "gitlab.com/gitlab-org/gitaly/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore" + "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/internal/praefect/transactions" @@ -53,6 +54,8 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { + defer glsql.Clean() + defer testhelper.MustHaveNoChildProcess() cleanup := testhelper.Configure() @@ -316,56 +319,6 @@ func TestReplicatorDowngradeAttempt(t *testing.T) { require.Equal(t, "repository downgrade prevented", hook.LastEntry().Message) } -type MockRepositoryService struct { - gitalypb.UnimplementedRepositoryServiceServer - ReplicateRepositoryFunc func(context.Context, *gitalypb.ReplicateRepositoryRequest) (*gitalypb.ReplicateRepositoryResponse, error) -} - -func (m *MockRepositoryService) ReplicateRepository(ctx context.Context, r *gitalypb.ReplicateRepositoryRequest) (*gitalypb.ReplicateRepositoryResponse, error) { - return m.ReplicateRepositoryFunc(ctx, r) -} - -func TestReplicatorInvalidSourceRepository(t *testing.T) { - ctx, cancel := testhelper.Context() - defer cancel() - - tmp, cleanDir := testhelper.TempDir(t) - defer cleanDir() - - socketPath := filepath.Join(tmp, "socket") - ln, err := net.Listen("unix", socketPath) - require.NoError(t, err) - - srv := grpc.NewServer() - gitalypb.RegisterRepositoryServiceServer(srv, &MockRepositoryService{ - ReplicateRepositoryFunc: func(context.Context, *gitalypb.ReplicateRepositoryRequest) (*gitalypb.ReplicateRepositoryResponse, error) { - return nil, repository.ErrInvalidSourceRepository - }, - }) - defer srv.Stop() - go srv.Serve(ln) - - targetCC, err := client.Dial(ln.Addr().Network()+":"+ln.Addr().String(), nil) - require.NoError(t, err) - - rs := datastore.NewMemoryRepositoryStore(nil) - require.NoError(t, rs.SetGeneration(ctx, "virtual-storage-1", "relative-path-1", "gitaly-1", 0)) - - r := &defaultReplicator{rs: rs, log: testhelper.DiscardTestLogger(t)} - require.NoError(t, r.Replicate(ctx, datastore.ReplicationEvent{ - Job: datastore.ReplicationJob{ - VirtualStorage: "virtual-storage-1", - RelativePath: "relative-path-1", - SourceNodeStorage: "gitaly-1", - TargetNodeStorage: "gitaly-2", - }, - }, nil, targetCC)) - - exists, err := rs.RepositoryExists(ctx, "virtual-storage-1", "relative-path-1") - require.NoError(t, err) - require.False(t, exists) -} - func TestPropagateReplicationJob(t *testing.T) { primaryServer, primarySocketPath, cleanup := runMockRepositoryServer(t) defer cleanup() |