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>2020-11-27 15:57:05 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2020-12-02 18:40:29 +0300
commitc2240cd46b921efc790bef8cea57921eecf74bd1 (patch)
treefd1ab0d73e021b14ab8569d054303797a31deea8 /internal/praefect/replicator_test.go
parentf6045c730eea37aef46d5ab7c9a894f34a9d01ef (diff)
test both lower and equal generation in TestReplicatorDowngradeAttempt
Diffstat (limited to 'internal/praefect/replicator_test.go')
-rw-r--r--internal/praefect/replicator_test.go73
1 files changed, 44 insertions, 29 deletions
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index a6648f9cc..243fb8b7f 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -267,41 +267,56 @@ func TestReplicatorDowngradeAttempt(t *testing.T) {
ctx = correlation.ContextWithCorrelation(ctx, "correlation-id")
- rs := datastore.MockRepositoryStore{
- GetReplicatedGenerationFunc: func(ctx context.Context, virtualStorage, relativePath, source, target string) (int, error) {
- return 0, datastore.DowngradeAttemptedError{
+ for _, tc := range []struct {
+ desc string
+ attemptedGeneration int
+ expectedMessage string
+ }{
+ {
+ desc: "same generation attempted",
+ attemptedGeneration: 1,
+ expectedMessage: "target repository already on the same generation, skipping replication job",
+ },
+ {
+ desc: "lower generation attempted",
+ attemptedGeneration: 0,
+ expectedMessage: "repository downgrade prevented",
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ returnedErr := datastore.DowngradeAttemptedError{
VirtualStorage: "virtual-storage-1",
RelativePath: "relative-path-1",
Storage: "gitaly-2",
- CurrentGeneration: 0,
- AttemptedGeneration: 0,
+ CurrentGeneration: 1,
+ AttemptedGeneration: tc.attemptedGeneration,
}
- },
- }
- logger := testhelper.DiscardTestLogger(t)
- hook := test.NewLocal(logger)
- r := &defaultReplicator{rs: rs, log: logger}
+ rs := datastore.MockRepositoryStore{
+ GetReplicatedGenerationFunc: func(ctx context.Context, virtualStorage, relativePath, source, target string) (int, error) {
+ return 0, returnedErr
+ },
+ }
- 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, nil))
-
- require.Equal(t, logrus.InfoLevel, hook.LastEntry().Level)
- require.Equal(t, datastore.DowngradeAttemptedError{
- VirtualStorage: "virtual-storage-1",
- RelativePath: "relative-path-1",
- Storage: "gitaly-2",
- CurrentGeneration: 0,
- AttemptedGeneration: 0,
- }, hook.LastEntry().Data["error"])
- require.Equal(t, "correlation-id", hook.LastEntry().Data[logWithCorrID])
- require.Equal(t, "target repository already on the same generation, skipping replication job", hook.LastEntry().Message)
+ logger := testhelper.DiscardTestLogger(t)
+ hook := test.NewLocal(logger)
+ r := &defaultReplicator{rs: rs, log: logger}
+
+ 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, nil))
+
+ require.Equal(t, logrus.InfoLevel, hook.LastEntry().Level)
+ require.Equal(t, returnedErr, hook.LastEntry().Data["error"])
+ require.Equal(t, "correlation-id", hook.LastEntry().Data[logWithCorrID])
+ require.Equal(t, tc.expectedMessage, hook.LastEntry().Message)
+ })
+ }
}
func TestPropagateReplicationJob(t *testing.T) {