diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-29 21:08:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-29 21:08:26 +0300 |
commit | b64a8161c9442d82897a341d6bf935dd3e748b06 (patch) | |
tree | b9953db8607d1393aa8ac588a15f184dd8e183f6 /spec/workers | |
parent | 6e33325c1458cb31b4d36a7eec817fa00ec3faaf (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb | 39 | ||||
-rw-r--r-- | spec/workers/stuck_import_jobs_worker_spec.rb | 47 |
2 files changed, 41 insertions, 45 deletions
diff --git a/spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb b/spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb new file mode 100644 index 00000000000..fae52cec2b4 --- /dev/null +++ b/spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Gitlab::JiraImport::StuckJiraImportJobsWorker do + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project) } + let(:worker) { described_class.new } + + describe 'with scheduled Jira import' do + it_behaves_like 'stuck import job detection' do + let(:import_state) { create(:jira_import_state, :scheduled, project: project) } + + before do + import_state.update(jid: '123') + end + end + end + + describe 'with started jira import' do + it_behaves_like 'stuck import job detection' do + let(:import_state) { create(:jira_import_state, :started, project: project) } + + before do + import_state.update(jid: '123') + end + end + end + + describe 'with failed jira import' do + let(:import_state) { create(:jira_import_state, :failed, project: project) } + + it 'detects no stuck jobs' do + expect(worker).to receive(:track_metrics).with(0, 0) + + worker.perform + end + end +end diff --git a/spec/workers/stuck_import_jobs_worker_spec.rb b/spec/workers/stuck_import_jobs_worker_spec.rb index dcb8e59ed28..f8d7f8747d5 100644 --- a/spec/workers/stuck_import_jobs_worker_spec.rb +++ b/spec/workers/stuck_import_jobs_worker_spec.rb @@ -5,51 +5,8 @@ require 'spec_helper' describe StuckImportJobsWorker do let(:worker) { described_class.new } - 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 - import_state.start - import_state.finish - - [import_state.jid] - end - end - - it 'does not mark the project as failed' do - worker.perform - - expect(import_state.reload.status).to eq('finished') - end - end - - context 'when the import status was not updated' do - before do - allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return([import_state.jid]) - end - - it 'marks the project as failed' do - worker.perform - - expect(import_state.reload.status).to eq('failed') - end - end - end - - context 'when the job is still in Sidekiq' do - before do - allow(Gitlab::SidekiqStatus).to receive(:completed_jids).and_return([]) - end - - it 'does not mark the project as failed' do - expect { worker.perform }.not_to change { import_state.reload.status } - end - end - end - describe 'with scheduled import_status' do - it_behaves_like 'project import job detection' do + it_behaves_like 'stuck import job detection' do let(:import_state) { create(:project, :import_scheduled).import_state } before do @@ -59,7 +16,7 @@ describe StuckImportJobsWorker do end describe 'with started import_status' do - it_behaves_like 'project import job detection' do + it_behaves_like 'stuck import job detection' do let(:import_state) { create(:project, :import_started).import_state } before do |