BigW Consortium Gitlab

stuck_import_jobs_worker_spec.rb 1.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
require 'spec_helper'

describe StuckImportJobsWorker do
  let(:worker) { described_class.new }
  let(:exclusive_lease_uuid) { SecureRandom.uuid }

  before do
    allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(exclusive_lease_uuid)
  end

11 12
  describe 'with started import_status' do
    let(:project) { create(:project, :import_started, import_jid: '123') }
13

14 15 16
    describe 'long running import' do
      it 'marks the project as failed' do
        allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return(['123'])
17

18 19
        expect { worker.perform }.to change { project.reload.import_status }.to('failed')
      end
20 21
    end

22 23 24
    describe 'running import' do
      it 'does not mark the project as failed' do
        allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return([])
25

26 27
        expect { worker.perform }.not_to change { project.reload.import_status }
      end
28

29 30 31 32 33
      describe 'import without import_jid' do
        it 'marks the project as failed' do
          expect { worker.perform }.to change { project.reload.import_status }.to('failed')
        end
      end
34 35 36
    end
  end
end