2019-05-18 00:54:41 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2018-12-13 13:39:08 +05:30
|
|
|
import_state.start
|
|
|
|
import_state.finish
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
[import_state.jid]
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not mark the project as failed' do
|
|
|
|
worker.perform
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(import_state.reload.status).to eq('finished')
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the import status was not updated' do
|
|
|
|
before do
|
2018-12-13 13:39:08 +05:30
|
|
|
allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return([import_state.jid])
|
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 'marks the project as failed' do
|
|
|
|
worker.perform
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(import_state.reload.status).to eq('failed')
|
2018-03-27 19:54:05 +05:30
|
|
|
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-12-13 13:39:08 +05:30
|
|
|
expect { worker.perform }.not_to change { import_state.reload.status }
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:import_state) { create(:project, :import_scheduled).import_state }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
before do
|
2018-12-13 13:39:08 +05:30
|
|
|
import_state.update(jid: '123')
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with started import_status' do
|
|
|
|
it_behaves_like 'project import job detection' do
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:import_state) { create(:project, :import_started).import_state }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
before do
|
2018-12-13 13:39:08 +05:30
|
|
|
import_state.update(jid: '123')
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|