debian-mirror-gitlab/spec/workers/stuck_import_jobs_worker_spec.rb

61 lines
1.6 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe StuckImportJobsWorker do
let(:worker) { described_class.new }
2018-03-27 19:54:05 +05:30
shared_examples 'project import job detection' do
context 'when the job has completed' do
context 'when the import status was already updated' do
before do
allow(Gitlab::SidekiqStatus).to receive(:completed_jids) do
project.import_start
project.import_finish
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
[project.import_jid]
end
end
it 'does not mark the project as failed' do
worker.perform
expect(project.reload.import_status).to eq('finished')
end
end
context 'when the import status was not updated' do
before do
allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return([project.import_jid])
end
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
it 'marks the project as failed' do
worker.perform
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
expect(project.reload.import_status).to eq('failed')
end
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
end
2018-03-27 19:54:05 +05:30
context 'when the job is still in Sidekiq' do
before do
2018-03-17 18:26:18 +05:30
allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return([])
2018-03-27 19:54:05 +05:30
end
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
it 'does not mark the project as failed' do
2018-03-17 18:26:18 +05:30
expect { worker.perform }.not_to change { project.reload.import_status }
end
2018-03-27 19:54:05 +05:30
end
end
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
describe 'with scheduled import_status' do
it_behaves_like 'project import job detection' do
let(:project) { create(:project, :import_scheduled, import_jid: '123') }
end
end
describe 'with started import_status' do
it_behaves_like 'project import job detection' do
let(:project) { create(:project, :import_started, import_jid: '123') }
2017-08-17 22:00:37 +05:30
end
end
end