diff options
Diffstat (limited to 'spec/lib/gitlab/database/migrations/test_background_runner_spec.rb')
-rw-r--r-- | spec/lib/gitlab/database/migrations/test_background_runner_spec.rb | 37 |
1 files changed, 3 insertions, 34 deletions
diff --git a/spec/lib/gitlab/database/migrations/test_background_runner_spec.rb b/spec/lib/gitlab/database/migrations/test_background_runner_spec.rb index 9407efad91f..a2fe91712c7 100644 --- a/spec/lib/gitlab/database/migrations/test_background_runner_spec.rb +++ b/spec/lib/gitlab/database/migrations/test_background_runner_spec.rb @@ -3,7 +3,9 @@ require 'spec_helper' RSpec.describe Gitlab::Database::Migrations::TestBackgroundRunner, :redis do + include Gitlab::Database::Migrations::ReestablishedConnectionStack include Gitlab::Database::Migrations::BackgroundMigrationHelpers + include Database::MigrationTestingHelpers # In order to test the interaction between queueing sidekiq jobs and seeing those jobs in queues, # we need to disable sidekiq's testing mode and actually send our jobs to redis @@ -12,6 +14,7 @@ RSpec.describe Gitlab::Database::Migrations::TestBackgroundRunner, :redis do end let(:result_dir) { Dir.mktmpdir } + let(:connection) { ApplicationRecord.connection } after do FileUtils.rm_rf(result_dir) @@ -41,40 +44,6 @@ RSpec.describe Gitlab::Database::Migrations::TestBackgroundRunner, :redis do end context 'running migrations', :freeze_time do - def define_background_migration(name) - klass = Class.new do - # Can't simply def perform here as we won't have access to the block, - # similarly can't define_method(:perform, &block) here as it would change the block receiver - define_method(:perform) { |*args| yield(*args) } - end - stub_const("Gitlab::BackgroundMigration::#{name}", klass) - klass - end - - def expect_migration_call_counts(migrations_to_calls) - migrations_to_calls.each do |migration, calls| - expect_next_instances_of(migration, calls) do |m| - expect(m).to receive(:perform).and_call_original - end - end - end - - def expect_recorded_migration_runs(migrations_to_runs) - migrations_to_runs.each do |migration, runs| - path = File.join(result_dir, migration.name.demodulize) - num_subdirs = Pathname(path).children.count(&:directory?) - expect(num_subdirs).to eq(runs) - end - end - - def expect_migration_runs(migrations_to_run_counts) - expect_migration_call_counts(migrations_to_run_counts) - - yield - - expect_recorded_migration_runs(migrations_to_run_counts) - end - it 'runs the migration class correctly' do calls = [] define_background_migration(migration_name) do |i| |