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:
authorFelipe Artur <felipefac@gmail.com>2019-03-12 22:55:20 +0300
committerFelipe Artur <felipefac@gmail.com>2019-03-12 22:55:20 +0300
commit029643ac5237fea97f3ede2b523162fd3106ec37 (patch)
treec8bb70180a47cae2873aa459c62eb83188fafbd2
parentc90dda9c441a61b0c472095cbb248c53fdb1deec (diff)
Add some specs
-rw-r--r--db/post_migrate/20190221234852_int4_pk_stage1of2_fill_column.rb2
-rw-r--r--spec/migrations/int4_pk_stage1of2_fill_column_spec.rb54
2 files changed, 55 insertions, 1 deletions
diff --git a/db/post_migrate/20190221234852_int4_pk_stage1of2_fill_column.rb b/db/post_migrate/20190221234852_int4_pk_stage1of2_fill_column.rb
index 4fa8c6d27af..4b073514013 100644
--- a/db/post_migrate/20190221234852_int4_pk_stage1of2_fill_column.rb
+++ b/db/post_migrate/20190221234852_int4_pk_stage1of2_fill_column.rb
@@ -1,7 +1,7 @@
class Int4PkStage1of2FillColumn < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
- disable_ddl_transaction!
+ disable_ddl_transaction!
DOWNTIME = false
diff --git a/spec/migrations/int4_pk_stage1of2_fill_column_spec.rb b/spec/migrations/int4_pk_stage1of2_fill_column_spec.rb
new file mode 100644
index 00000000000..68d3c861493
--- /dev/null
+++ b/spec/migrations/int4_pk_stage1of2_fill_column_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20190221234852_int4_pk_stage1of2_fill_column.rb')
+
+describe Int4PkStage1of2FillColumn, :migration do
+ let(:users) { table(:users) }
+ let(:events) {table(:events) }
+
+ before do
+ Sidekiq::Worker.clear_all
+ stub_const("#{described_class.name}::BATCH_SIZE", 2)
+ @user = users.create!(projects_limit: 10, name: 'The User')
+ end
+
+ describe '#up' do
+ context 'events' do
+ it 'migrates id column values to id_new' do
+ 3.times do
+ events.create!(author_id: @user.id, action: 'Open something')
+ end
+
+ migrate!
+
+ Event.all.limit(3).each do |event|
+ expect(event.id_new).to eq(event.id)
+ end
+ end
+
+ it 'schedules migration correctly' do
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migration = described_class::MIGRATION
+ concurrency = described_class::CONCURRENCY
+ delay = described_class::DELAY
+ batch_size = described_class::BATCH_SIZE
+ batches_in_iteration = described_class::BATCHES_IN_ITERATION
+
+ migrate!
+
+ # Check how many times the migration has been scheduled
+ # deleting the last job that updates the table and then checking again
+ # Move to custom matcher?
+ concurrency.times do
+ expect(migration).to be_scheduled_delayed_migration(120, 'events', 'id', 'id_new', delay, batch_size, batches_in_iteration)
+ job_index = BackgroundMigrationWorker.jobs.index { |job| job['args'][1][0] == 'events' }
+ BackgroundMigrationWorker.jobs.delete_at(job_index)
+ end
+ end
+ end
+ end
+ end
+ end
+end