diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/lib/gitlab/jira_import | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/lib/gitlab/jira_import')
-rw-r--r-- | spec/lib/gitlab/jira_import/issues_importer_spec.rb | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/spec/lib/gitlab/jira_import/issues_importer_spec.rb b/spec/lib/gitlab/jira_import/issues_importer_spec.rb index 1bc052ee0b6..a2a482dde7c 100644 --- a/spec/lib/gitlab/jira_import/issues_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/issues_importer_spec.rb @@ -40,7 +40,7 @@ RSpec.describe Gitlab::JiraImport::IssuesImporter do context 'with results returned' do jira_issue = Struct.new(:id) - let_it_be(:jira_issues) { [jira_issue.new(1), jira_issue.new(2)] } + let_it_be(:jira_issues) { [jira_issue.new(1), jira_issue.new(2), jira_issue.new(3)] } def mock_issue_serializer(count, raise_exception_on_even_mocks: false) serializer = instance_double(Gitlab::JiraImport::IssueSerializer, execute: { key: 'data' }) @@ -125,6 +125,47 @@ RSpec.describe Gitlab::JiraImport::IssuesImporter do expect(Gitlab::JiraImport.get_issues_next_start_at(project.id)).to eq(2) end end + + context 'when number of issues is above the threshold' do + before do + stub_const("#{described_class.name}::JIRA_IMPORT_THRESHOLD", 2) + stub_const("#{described_class.name}::JIRA_IMPORT_PAUSE_LIMIT", 1) + allow(Gitlab::ErrorTracking).to receive(:track_exception) + allow_next_instance_of(Gitlab::JobWaiter) do |job_waiter| + allow(job_waiter).to receive(:wait).with(5).and_return(job_waiter.wait(0.1)) + end + end + + it 'schedules 2 import jobs with two pause points' do + expect(subject).to receive(:fetch_issues).with(0).and_return([jira_issues[0], jira_issues[1], jira_issues[2]]) + expect(Gitlab::JiraImport::ImportIssueWorker).to receive(:perform_async).exactly(3).times + expect(Gitlab::JiraImport::ImportIssueWorker) + .to receive(:queue_size) + .exactly(6).times + .and_return(1, 2, 3, 2, 1, 0) + + mock_issue_serializer(3) + + expect(subject.execute).to have_received(:wait).with(5).twice + end + + it 'tracks the exception if the queue size does not reduce' do + expect(subject).to receive(:fetch_issues).with(0).and_return([jira_issues[0]]) + expect(Gitlab::JiraImport::ImportIssueWorker).not_to receive(:perform_async) + expect(Gitlab::JiraImport::ImportIssueWorker) + .to receive(:queue_size) + .exactly(11).times + .and_return(3) + + mock_issue_serializer(1) + + expect(subject.execute).to have_received(:wait).with(5).exactly(10).times + expect(Gitlab::ErrorTracking) + .to have_received(:track_exception) + .with(described_class::RetriesExceededError, { project_id: project.id }) + .once + end + end end end end |