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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::BitbucketImport::Importers::PullRequestsImporter, feature_category: :importers do
let_it_be(:project) do
create(:project, :import_started,
import_data_attributes: {
data: { 'project_key' => 'key', 'repo_slug' => 'slug' },
credentials: { 'base_uri' => 'http://bitbucket.org/', 'user' => 'bitbucket', 'password' => 'password' }
}
)
end
subject(:importer) { described_class.new(project) }
describe '#execute', :clean_gitlab_redis_cache do
before do
allow_next_instance_of(Bitbucket::Client) do |client|
allow(client).to receive(:pull_requests).and_return(
[
Bitbucket::Representation::PullRequest.new({ 'id' => 1, 'state' => 'OPENED' }),
Bitbucket::Representation::PullRequest.new({ 'id' => 2, 'state' => 'DECLINED' }),
Bitbucket::Representation::PullRequest.new({ 'id' => 3, 'state' => 'MERGED' })
],
[]
)
end
end
it 'imports each pull request in parallel', :aggregate_failures do
expect(Gitlab::BitbucketImport::ImportPullRequestWorker).to receive(:perform_in).exactly(3).times
waiter = importer.execute
expect(waiter).to be_an_instance_of(Gitlab::JobWaiter)
expect(waiter.jobs_remaining).to eq(3)
expect(Gitlab::Cache::Import::Caching.values_from_set(importer.already_enqueued_cache_key))
.to match_array(%w[1 2 3])
end
context 'when the client raises an error' do
before do
allow_next_instance_of(Bitbucket::Client) do |client|
allow(client).to receive(:pull_requests).and_raise(StandardError)
end
end
it 'tracks the failure and does not fail' do
expect(Gitlab::Import::ImportFailureService).to receive(:track).once
importer.execute
end
end
context 'when pull request was already enqueued' do
before do
Gitlab::Cache::Import::Caching.set_add(importer.already_enqueued_cache_key, 1)
end
it 'does not schedule job for enqueued pull requests', :aggregate_failures do
expect(Gitlab::BitbucketImport::ImportPullRequestWorker).to receive(:perform_in).twice
waiter = importer.execute
expect(waiter).to be_an_instance_of(Gitlab::JobWaiter)
expect(waiter.jobs_remaining).to eq(3)
end
end
end
end
|