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/lib/gitlab/background_migration/backfill_user_namespace_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb b/spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb
new file mode 100644
index 00000000000..395248b786d
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::BackfillUserNamespace, :migration, schema: 20210930211936 do
+ let(:migration) { described_class.new }
+ let(:namespaces_table) { table(:namespaces) }
+
+ let(:table_name) { 'namespaces' }
+ let(:batch_column) { :id }
+ let(:sub_batch_size) { 100 }
+ let(:pause_ms) { 0 }
+
+ subject(:perform_migration) { migration.perform(1, 10, table_name, batch_column, sub_batch_size, pause_ms) }
+
+ before do
+ namespaces_table.create!(id: 1, name: 'test1', path: 'test1', type: nil)
+ namespaces_table.create!(id: 2, name: 'test2', path: 'test2', type: 'User')
+ namespaces_table.create!(id: 3, name: 'test3', path: 'test3', type: 'Group')
+ namespaces_table.create!(id: 4, name: 'test4', path: 'test4', type: nil)
+ namespaces_table.create!(id: 11, name: 'test11', path: 'test11', type: nil)
+ end
+
+ it 'backfills `type` for the selected records', :aggregate_failures do
+ queries = ActiveRecord::QueryRecorder.new do
+ perform_migration
+ end
+
+ expect(queries.count).to eq(3)
+ expect(namespaces_table.where(type: 'User').count).to eq 3
+ expect(namespaces_table.where(type: 'User').pluck(:id)).to match_array([1, 2, 4])
+ end
+
+ it 'tracks timings of queries' do
+ expect(migration.batch_metrics.timings).to be_empty
+
+ expect { perform_migration }.to change { migration.batch_metrics.timings }
+ end
+end