summaryrefslogtreecommitdiff
path: root/spec/migrations/replace_work_item_type_backfill_next_batch_strategy_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations/replace_work_item_type_backfill_next_batch_strategy_spec.rb')
-rw-r--r--spec/migrations/replace_work_item_type_backfill_next_batch_strategy_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/migrations/replace_work_item_type_backfill_next_batch_strategy_spec.rb b/spec/migrations/replace_work_item_type_backfill_next_batch_strategy_spec.rb
new file mode 100644
index 00000000000..5e22fc06973
--- /dev/null
+++ b/spec/migrations/replace_work_item_type_backfill_next_batch_strategy_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe ReplaceWorkItemTypeBackfillNextBatchStrategy, :migration do
+ describe '#up' do
+ it 'sets the new strategy for existing migrations' do
+ migrations = create_migrations(described_class::OLD_STRATEGY_CLASS, 2)
+
+ expect do
+ migrate!
+
+ migrations.each(&:reload)
+ end.to change { migrations.pluck(:batch_class_name).uniq }.from([described_class::OLD_STRATEGY_CLASS])
+ .to([described_class::NEW_STRATEGY_CLASS])
+ end
+ end
+
+ describe '#down' do
+ it 'sets the old strategy for existing migrations' do
+ migrations = create_migrations(described_class::NEW_STRATEGY_CLASS, 2)
+
+ expect do
+ migrate!
+ schema_migrate_down!
+
+ migrations.each(&:reload)
+ end.to change { migrations.pluck(:batch_class_name).uniq }.from([described_class::NEW_STRATEGY_CLASS])
+ .to([described_class::OLD_STRATEGY_CLASS])
+ end
+ end
+
+ def create_migrations(batch_class_name, count)
+ Array.new(2) { |index| create_background_migration(batch_class_name, [index]) }
+ end
+
+ def create_background_migration(batch_class_name, job_arguments)
+ migrations_table = table(:batched_background_migrations)
+
+ migrations_table.create!(
+ batch_class_name: batch_class_name,
+ job_class_name: described_class::JOB_CLASS_NAME,
+ max_value: 10,
+ batch_size: 5,
+ sub_batch_size: 1,
+ interval: 2.minutes,
+ table_name: :issues,
+ column_name: :id,
+ total_tuple_count: 10_000,
+ pause_ms: 100,
+ job_arguments: job_arguments
+ )
+ end
+end