1
2
3
4
5
6
7
8
9
10
11
12
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
44
45
46
47
48
49
50
51
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, feature_category: :importer do
subject(:worker) { described_class.new }
let_it_be(:user) { create(:user) }
describe '#perform', :aggregate_failures do
context 'when there are no remaining jobs' do
it 'marks import status as finished' do
waiter = instance_double(Gitlab::JobWaiter, key: :key, jobs_remaining: 0)
expect(Gitlab::JobWaiter).to receive(:new).and_return(waiter)
expect(waiter).to receive(:wait).with(described_class::BLOCKING_WAIT_TIME)
expect_next_instance_of(Gitlab::GithubGistsImport::Status) do |status|
expect(status).to receive(:finish!)
end
expect(Gitlab::GithubImport::Logger)
.to receive(:info)
.with(user_id: user.id, message: 'GitHub Gists import finished')
worker.perform(user.id, waiter.key, waiter.jobs_remaining)
end
end
context 'when there are remaining jobs' do
it 'reschedules the worker' do
waiter = instance_double(Gitlab::JobWaiter, key: :key, jobs_remaining: 2)
expect(Gitlab::JobWaiter).to receive(:new).and_return(waiter)
expect(waiter).to receive(:wait).with(described_class::BLOCKING_WAIT_TIME)
expect(described_class).to receive(:perform_in)
.with(described_class::INTERVAL, user.id, waiter.key, waiter.jobs_remaining)
worker.perform(user.id, waiter.key, waiter.jobs_remaining)
end
end
end
describe '.sidekiq_retries_exhausted' do
it 'sets status to failed' do
job = { 'args' => [user.id, 'some_key', '1'], 'jid' => '123' }
expect_next_instance_of(Gitlab::GithubGistsImport::Status) do |status|
expect(status).to receive(:fail!)
end
described_class.sidekiq_retries_exhausted_block.call(job)
end
end
end
|