2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::GithubImport::RefreshImportJidWorker do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:worker) { described_class.new }
|
|
|
|
|
|
|
|
describe '.perform_in_the_future' do
|
|
|
|
it 'schedules a job in the future' do
|
|
|
|
expect(described_class)
|
|
|
|
.to receive(:perform_in)
|
|
|
|
.with(1.minute.to_i, 10, '123')
|
|
|
|
|
|
|
|
described_class.perform_in_the_future(10, '123')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#perform' do
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:import_state) { create(:import_state, project: project, jid: '123abc') }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'when the project does not exist' do
|
|
|
|
it 'does nothing' do
|
|
|
|
expect(Gitlab::SidekiqStatus)
|
|
|
|
.not_to receive(:running?)
|
|
|
|
|
|
|
|
worker.perform(-1, '123')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the job is running' do
|
|
|
|
it 'refreshes the import JID and reschedules itself' do
|
|
|
|
allow(worker)
|
2019-02-15 15:39:39 +05:30
|
|
|
.to receive(:find_import_state)
|
2018-03-17 18:26:18 +05:30
|
|
|
.with(project.id)
|
|
|
|
.and_return(project)
|
|
|
|
|
|
|
|
expect(Gitlab::SidekiqStatus)
|
|
|
|
.to receive(:running?)
|
|
|
|
.with('123')
|
|
|
|
.and_return(true)
|
|
|
|
|
|
|
|
expect(project)
|
2019-02-15 15:39:39 +05:30
|
|
|
.to receive(:refresh_jid_expiration)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(worker.class)
|
|
|
|
.to receive(:perform_in_the_future)
|
|
|
|
.with(project.id, '123')
|
|
|
|
|
|
|
|
worker.perform(project.id, '123')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the job is no longer running' do
|
|
|
|
it 'returns' do
|
|
|
|
allow(worker)
|
2019-02-15 15:39:39 +05:30
|
|
|
.to receive(:find_import_state)
|
2018-03-17 18:26:18 +05:30
|
|
|
.with(project.id)
|
|
|
|
.and_return(project)
|
|
|
|
|
|
|
|
expect(Gitlab::SidekiqStatus)
|
|
|
|
.to receive(:running?)
|
|
|
|
.with('123')
|
|
|
|
.and_return(false)
|
|
|
|
|
|
|
|
expect(project)
|
2019-02-15 15:39:39 +05:30
|
|
|
.not_to receive(:refresh_jid_expiration)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
worker.perform(project.id, '123')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe '#find_import_state' do
|
|
|
|
it 'returns a ProjectImportState' do
|
2018-10-15 14:42:47 +05:30
|
|
|
project = create(:project, :import_started)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(worker.find_import_state(project.id)).to be_an_instance_of(ProjectImportState)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
# it 'only selects the import JID field' do
|
|
|
|
# project = create(:project, :import_started)
|
|
|
|
# project.import_state.update_attributes(jid: '123abc')
|
|
|
|
#
|
|
|
|
# expect(worker.find_project(project.id).attributes)
|
|
|
|
# .to eq({ 'id' => nil, 'import_jid' => '123abc' })
|
|
|
|
# end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it 'returns nil for a import state for which the import process failed' do
|
2018-10-15 14:42:47 +05:30
|
|
|
project = create(:project, :import_failed)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(worker.find_import_state(project.id)).to be_nil
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it 'returns nil for a non-existing find_import_state' do
|
|
|
|
expect(worker.find_import_state(-1)).to be_nil
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|