summaryrefslogtreecommitdiff
path: root/spec/migrations
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-05-02 14:35:04 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-05-04 17:33:26 +0200
commitbddbcaefc2389e4c61763472cecbea150f10cd75 (patch)
tree38ba599beed53505dfca09fce7a890bf3b125bb3 /spec/migrations
parent7603beffc916d06039cac63b223d8e6234b5d666 (diff)
downloadgitlab-ce-bddbcaefc2389e4c61763472cecbea150f10cd75.tar.gz
Backports every CE related change from ee-44542 to CE
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/migrate_import_attributes_data_from_projects_to_project_mirror_data_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/migrations/migrate_import_attributes_data_from_projects_to_project_mirror_data_spec.rb b/spec/migrations/migrate_import_attributes_data_from_projects_to_project_mirror_data_spec.rb
new file mode 100644
index 00000000000..972c6dffc6f
--- /dev/null
+++ b/spec/migrations/migrate_import_attributes_data_from_projects_to_project_mirror_data_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20180502134117_migrate_import_attributes_data_from_projects_to_project_mirror_data.rb')
+
+describe MigrateImportAttributesDataFromProjectsToProjectMirrorData, :sidekiq, :migration do
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:import_state) { table(:project_mirror_data) }
+
+ before do
+ stub_const("#{described_class}::BATCH_SIZE", 1)
+ namespaces.create(id: 1, name: 'gitlab-org', path: 'gitlab-org')
+
+ projects.create!(id: 1, namespace_id: 1, name: 'gitlab1',
+ path: 'gitlab1', import_error: "foo", import_status: :started,
+ import_url: generate(:url))
+ projects.create!(id: 2, namespace_id: 1, name: 'gitlab2',
+ path: 'gitlab2', import_error: "bar", import_status: :failed,
+ import_url: generate(:url))
+ projects.create!(id: 3, namespace_id: 1, name: 'gitlab3', path: 'gitlab3', import_status: :none, import_url: generate(:url))
+ end
+
+ it 'schedules delayed background migrations in batches in bulk' do
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ expect(projects.where.not(import_status: :none).count).to eq(2)
+
+ subject.up
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq 2
+ expect(described_class::UP_MIGRATION).to be_scheduled_delayed_migration(5.minutes, 1, 1)
+ expect(described_class::UP_MIGRATION).to be_scheduled_delayed_migration(10.minutes, 2, 2)
+ end
+ end
+ end
+
+ describe '#down' do
+ before do
+ import_state.create!(id: 1, project_id: 1, status: :started)
+ import_state.create!(id: 2, project_id: 2, status: :started)
+ end
+
+ it 'schedules delayed background migrations in batches in bulk for rollback' do
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ expect(import_state.where.not(status: :none).count).to eq(2)
+
+ subject.down
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq 2
+ expect(described_class::DOWN_MIGRATION).to be_scheduled_delayed_migration(5.minutes, 1, 1)
+ expect(described_class::DOWN_MIGRATION).to be_scheduled_delayed_migration(10.minutes, 2, 2)
+ end
+ end
+ end
+ end
+end