Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/database')
-rw-r--r--spec/workers/database/batched_background_migration/ci_database_worker_spec.rb2
-rw-r--r--spec/workers/database/batched_background_migration_worker_spec.rb2
-rw-r--r--spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb67
-rw-r--r--spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb67
4 files changed, 136 insertions, 2 deletions
diff --git a/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb b/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb
index 2663c650986..f3cf5450048 100644
--- a/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb
+++ b/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb
@@ -3,5 +3,5 @@
require 'spec_helper'
RSpec.describe Database::BatchedBackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state do
- it_behaves_like 'it runs batched background migration jobs', 'ci'
+ it_behaves_like 'it runs batched background migration jobs', 'ci', feature_flag: :execute_batched_migrations_on_schedule_ci_database
end
diff --git a/spec/workers/database/batched_background_migration_worker_spec.rb b/spec/workers/database/batched_background_migration_worker_spec.rb
index a6c7db60abe..7f0883def3c 100644
--- a/spec/workers/database/batched_background_migration_worker_spec.rb
+++ b/spec/workers/database/batched_background_migration_worker_spec.rb
@@ -3,5 +3,5 @@
require 'spec_helper'
RSpec.describe Database::BatchedBackgroundMigrationWorker do
- it_behaves_like 'it runs batched background migration jobs', :main
+ it_behaves_like 'it runs batched background migration jobs', :main, feature_flag: :execute_batched_migrations_on_schedule
end
diff --git a/spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb b/spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb
new file mode 100644
index 00000000000..116026ea8f7
--- /dev/null
+++ b/spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Database::CiNamespaceMirrorsConsistencyCheckWorker do
+ let(:worker) { described_class.new }
+
+ describe '#perform' do
+ context 'feature flag is disabled' do
+ before do
+ stub_feature_flags(ci_namespace_mirrors_consistency_check: false)
+ end
+
+ it 'does not perform the consistency check on namespaces' do
+ expect(Database::ConsistencyCheckService).not_to receive(:new)
+ expect(worker).not_to receive(:log_extra_metadata_on_done)
+ worker.perform
+ end
+ end
+
+ context 'feature flag is enabled' do
+ before do
+ stub_feature_flags(ci_namespace_mirrors_consistency_check: true)
+ end
+
+ it 'executes the consistency check on namespaces' do
+ expect(Database::ConsistencyCheckService).to receive(:new).and_call_original
+ expected_result = { batches: 0, matches: 0, mismatches: 0, mismatches_details: [] }
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:results, expected_result)
+ worker.perform
+ end
+ end
+
+ context 'logs should contain the detailed mismatches' do
+ let(:first_namespace) { Namespace.all.order(:id).limit(1).first }
+ let(:missing_namespace) { Namespace.all.order(:id).limit(2).last }
+
+ before do
+ redis_shared_state_cleanup!
+ stub_feature_flags(ci_namespace_mirrors_consistency_check: true)
+ create_list(:namespace, 10) # This will also create Ci::NameSpaceMirror objects
+ missing_namespace.delete
+
+ allow_next_instance_of(Database::ConsistencyCheckService) do |instance|
+ allow(instance).to receive(:random_start_id).and_return(Namespace.first.id)
+ end
+ end
+
+ it 'reports the differences to the logs' do
+ expected_result = {
+ batches: 1,
+ matches: 9,
+ mismatches: 1,
+ mismatches_details: [{
+ id: missing_namespace.id,
+ source_table: nil,
+ target_table: [missing_namespace.traversal_ids]
+ }],
+ start_id: first_namespace.id,
+ next_start_id: first_namespace.id # The batch size > number of namespaces
+ }
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:results, expected_result)
+ worker.perform
+ end
+ end
+ end
+end
diff --git a/spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb b/spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb
new file mode 100644
index 00000000000..b6bd825ffcd
--- /dev/null
+++ b/spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Database::CiProjectMirrorsConsistencyCheckWorker do
+ let(:worker) { described_class.new }
+
+ describe '#perform' do
+ context 'feature flag is disabled' do
+ before do
+ stub_feature_flags(ci_project_mirrors_consistency_check: false)
+ end
+
+ it 'does not perform the consistency check on projects' do
+ expect(Database::ConsistencyCheckService).not_to receive(:new)
+ expect(worker).not_to receive(:log_extra_metadata_on_done)
+ worker.perform
+ end
+ end
+
+ context 'feature flag is enabled' do
+ before do
+ stub_feature_flags(ci_project_mirrors_consistency_check: true)
+ end
+
+ it 'executes the consistency check on projects' do
+ expect(Database::ConsistencyCheckService).to receive(:new).and_call_original
+ expected_result = { batches: 0, matches: 0, mismatches: 0, mismatches_details: [] }
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:results, expected_result)
+ worker.perform
+ end
+ end
+
+ context 'logs should contain the detailed mismatches' do
+ let(:first_project) { Project.all.order(:id).limit(1).first }
+ let(:missing_project) { Project.all.order(:id).limit(2).last }
+
+ before do
+ redis_shared_state_cleanup!
+ stub_feature_flags(ci_project_mirrors_consistency_check: true)
+ create_list(:project, 10) # This will also create Ci::NameSpaceMirror objects
+ missing_project.delete
+
+ allow_next_instance_of(Database::ConsistencyCheckService) do |instance|
+ allow(instance).to receive(:random_start_id).and_return(Project.first.id)
+ end
+ end
+
+ it 'reports the differences to the logs' do
+ expected_result = {
+ batches: 1,
+ matches: 9,
+ mismatches: 1,
+ mismatches_details: [{
+ id: missing_project.id,
+ source_table: nil,
+ target_table: [missing_project.namespace_id]
+ }],
+ start_id: first_project.id,
+ next_start_id: first_project.id # The batch size > number of projects
+ }
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:results, expected_result)
+ worker.perform
+ end
+ end
+ end
+end