background_migration_worker_spec.rb 1.22 KB
Newer Older
1 2
require 'spec_helper'

3
describe BackgroundMigrationWorker, :sidekiq do
4 5
  describe '.perform' do
    it 'performs a background migration' do
6 7 8
      expect(Gitlab::BackgroundMigration)
        .to receive(:perform)
        .with('Foo', [10, 20])
9 10 11 12

      described_class.new.perform('Foo', [10, 20])
    end
  end
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

  describe '.perform_bulk' do
    it 'enqueues background migrations in bulk' do
      Sidekiq::Testing.fake! do
        described_class.perform_bulk([['Foo', [1]], ['Foo', [2]]])

        expect(described_class.jobs.count).to eq 2
        expect(described_class.jobs).to all(include('enqueued_at'))
      end
    end
  end

  describe '.perform_bulk_in' do
    context 'when delay is valid' do
      it 'correctly schedules background migrations' do
        Sidekiq::Testing.fake! do
          described_class.perform_bulk_in(1.minute, [['Foo', [1]], ['Foo', [2]]])

          expect(described_class.jobs.count).to eq 2
          expect(described_class.jobs).to all(include('at'))
        end
      end
    end

    context 'when delay is invalid' do
      it 'raises an ArgumentError exception' do
        expect { described_class.perform_bulk_in(-60, [['Foo']]) }
          .to raise_error(ArgumentError)
      end
    end
  end
44
end