diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 12:09:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 12:09:24 +0000 |
commit | a9ced7da447785c57477b3d8dbccc73a78cface1 (patch) | |
tree | 5179d27ab9d801748ee4ed1c64c985974e799812 /spec/workers | |
parent | ad0265eead72a624ce7a020847db4f0f0c877e57 (diff) | |
download | gitlab-ce-a9ced7da447785c57477b3d8dbccc73a78cface1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
7 files changed, 70 insertions, 99 deletions
diff --git a/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb b/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb index b6db803ddf5..80629cb875e 100644 --- a/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' describe Gitlab::JiraImport::ImportIssueWorker do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } + let(:some_key) { 'some-key' } describe 'modules' do it { expect(described_class).to include_module(ApplicationWorker) } @@ -23,7 +24,7 @@ describe Gitlab::JiraImport::ImportIssueWorker do allow(subject).to receive(:insert_and_return_id).and_raise(StandardError) expect(Gitlab::JobWaiter).to receive(:notify) - subject.perform(project.id, 123, issue_attrs, 'some-key') + subject.perform(project.id, 123, issue_attrs, some_key) end it 'record a failed to import issue' do @@ -36,7 +37,7 @@ describe Gitlab::JiraImport::ImportIssueWorker do context 'when import label does not exist' do it 'does not record import failure' do - subject.perform(project.id, 123, issue_attrs, 'some-key') + subject.perform(project.id, 123, issue_attrs, some_key) expect(label.issues.count).to eq(0) expect(Gitlab::Cache::Import::Caching.read(Gitlab::JiraImport.failed_issues_counter_cache_key(project.id)).to_i).to eq(0) @@ -49,7 +50,7 @@ describe Gitlab::JiraImport::ImportIssueWorker do end it 'does not record import failure' do - subject.perform(project.id, 123, issue_attrs, 'some-key') + subject.perform(project.id, 123, issue_attrs, some_key) expect(label.issues.count).to eq(1) expect(Gitlab::Cache::Import::Caching.read(Gitlab::JiraImport.failed_issues_counter_cache_key(project.id)).to_i).to eq(0) diff --git a/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb index 00505226212..93e2a44223b 100644 --- a/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb @@ -16,46 +16,29 @@ describe Gitlab::JiraImport::Stage::FinishImportWorker do stub_feature_flags(jira_issue_import: false) end - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' end context 'when feature flag enabled' do + let_it_be(:jira_import) { create(:jira_import_state, :scheduled, project: project) } + before do stub_feature_flags(jira_issue_import: true) end context 'when import did not start' do - let!(:import_state) { create(:import_state, project: project) } - - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' end context 'when import started' do - let(:imported_jira_project) do - JiraImportData::JiraProjectDetails.new('xx', Time.now.strftime('%Y-%m-%d %H:%M:%S'), { user_id: 1, name: 'root' }) + before do + jira_import.start! end - let(:jira_import_data) do - data = JiraImportData.new - data << imported_jira_project - data.force_import! - data - end - let(:import_state) { create(:import_state, status: :started) } - let(:project) { create(:project, import_type: 'jira', import_data: jira_import_data, import_state: import_state) } it 'changes import state to finished' do worker.perform(project.id) - expect(project.reload.import_state.status).to eq("finished") - end - - it 'removes force-import flag' do - expect(project.reload.import_data.data['jira'][JiraImportData::FORCE_IMPORT_KEY]).to be true - - worker.perform(project.id) - - expect(project.reload.import_data.data['jira'][JiraImportData::FORCE_IMPORT_KEY]).to be nil - expect(project.reload.import_data.data['jira']).not_to be nil + expect(project.jira_import_status).to eq('finished') end end end diff --git a/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb index 513925507a1..478cb447dc5 100644 --- a/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb @@ -3,34 +3,38 @@ require 'spec_helper' describe Gitlab::JiraImport::Stage::ImportAttachmentsWorker do - let_it_be(:project) { create(:project) } + let_it_be(:project) { create(:project, import_type: 'jira') } describe 'modules' do it_behaves_like 'include import workers modules' end describe '#perform' do - context 'when feature flag enabled' do + context 'when feature flag disabled' do before do stub_feature_flags(jira_issue_import: false) end - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when feature flag enabled' do + let_it_be(:jira_import) { create(:jira_import_state, :scheduled, project: project) } + before do stub_feature_flags(jira_issue_import: true) end context 'when import did not start' do - let!(:import_state) { create(:import_state, project: project) } - - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when import started' do - let!(:import_state) { create(:import_state, status: :started, project: project) } + before do + jira_import.start! + end it_behaves_like 'advance to next stage', :notes end diff --git a/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb index dca748a6ebc..6470a293461 100644 --- a/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb @@ -4,43 +4,39 @@ require 'spec_helper' describe Gitlab::JiraImport::Stage::ImportIssuesWorker do let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } + let_it_be(:project) { create(:project, import_type: 'jira') } describe 'modules' do it_behaves_like 'include import workers modules' end describe '#perform' do - context 'when feature flag enabled' do + context 'when feature flag disabled' do before do stub_feature_flags(jira_issue_import: false) end - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when feature flag enabled' do + let_it_be(:jira_import, reload: true) { create(:jira_import_state, :scheduled, project: project) } + before do stub_feature_flags(jira_issue_import: true) end context 'when import did not start' do - let!(:import_state) { create(:import_state, project: project) } - - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when import started', :clean_gitlab_redis_cache do - let(:jira_import_data) do - data = JiraImportData.new - data << JiraImportData::JiraProjectDetails.new('XX', Time.now.strftime('%Y-%m-%d %H:%M:%S'), { user_id: user.id, name: user.name }) - data - end - let(:project) { create(:project, import_data: jira_import_data) } - let!(:jira_service) { create(:jira_service, project: project) } - let!(:import_state) { create(:import_state, status: :started, project: project) } + let_it_be(:jira_service) { create(:jira_service, project: project) } before do + jira_import.start! allow_next_instance_of(Gitlab::JiraImport::IssuesImporter) do |instance| allow(instance).to receive(:fetch_issues).and_return([]) end diff --git a/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb index a3e38cba115..f1562395546 100644 --- a/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb @@ -4,41 +4,40 @@ require 'spec_helper' describe Gitlab::JiraImport::Stage::ImportLabelsWorker do let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } + let_it_be(:project) { create(:project, import_type: 'jira') } describe 'modules' do it_behaves_like 'include import workers modules' end describe '#perform' do - context 'when feature flag enabled' do + context 'when feature flag disabled' do before do stub_feature_flags(jira_issue_import: false) end - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when feature flag enabled' do + let_it_be(:jira_import, reload: true) { create(:jira_import_state, :scheduled, project: project) } + before do stub_feature_flags(jira_issue_import: true) end context 'when import did not start' do - let!(:import_state) { create(:import_state, project: project) } - - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when import started' do - let(:jira_import_data) do - data = JiraImportData.new - data << JiraImportData::JiraProjectDetails.new('XX', Time.now.strftime('%Y-%m-%d %H:%M:%S'), { user_id: user.id, name: user.name }) - data - end - let(:project) { create(:project, import_data: jira_import_data) } let!(:jira_service) { create(:jira_service, project: project) } - let!(:import_state) { create(:import_state, status: :started, project: project) } + + before do + jira_import.start! + end it_behaves_like 'advance to next stage', :issues diff --git a/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb index 7d1c29614e4..956898c1abc 100644 --- a/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb @@ -3,34 +3,38 @@ require 'spec_helper' describe Gitlab::JiraImport::Stage::ImportNotesWorker do - let_it_be(:project) { create(:project) } + let_it_be(:project) { create(:project, import_type: 'jira') } describe 'modules' do it_behaves_like 'include import workers modules' end describe '#perform' do - context 'when feature flag enabled' do + context 'when feature flag disabled' do before do stub_feature_flags(jira_issue_import: false) end - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when feature flag enabled' do + let_it_be(:jira_import) { create(:jira_import_state, :scheduled, project: project) } + before do stub_feature_flags(jira_issue_import: true) end context 'when import did not start' do - let!(:import_state) { create(:import_state, project: project) } - - it_behaves_like 'exit import not started' + it_behaves_like 'cannot do jira import' + it_behaves_like 'does not advance to next stage' end context 'when import started' do - let!(:import_state) { create(:import_state, status: :started, project: project) } + before do + jira_import.start! + end it_behaves_like 'advance to next stage', :finish end diff --git a/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb index d5e10a950bb..9cffe6e4ff7 100644 --- a/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' describe Gitlab::JiraImport::Stage::StartImportWorker do - let(:project) { create(:project, import_type: 'jira') } + let_it_be(:project) { create(:project, import_type: 'jira') } + let_it_be(:jid) { '12345678' } let(:worker) { described_class.new } - let(:jid) { '12345678' } describe 'modules' do it_behaves_like 'include import workers modules' end describe '#perform' do - context 'when feature flag not enabled' do + context 'when feature flag not disabled' do before do stub_feature_flags(jira_issue_import: false) end @@ -25,19 +25,13 @@ describe Gitlab::JiraImport::Stage::StartImportWorker do end context 'when feature flag enabled' do - let(:symbol_keys_project) do - { key: 'AA', scheduled_at: 2.days.ago.strftime('%Y-%m-%d %H:%M:%S'), scheduled_by: { 'user_id' => 1, 'name' => 'tester1' } } - end - let(:import_data) { JiraImportData.new( data: { 'jira' => { JiraImportData::FORCE_IMPORT_KEY => true, projects: [symbol_keys_project] } }) } + let_it_be(:jira_import, reload: true) { create(:jira_import_state, project: project, jid: jid) } before do stub_feature_flags(jira_issue_import: true) end context 'when import is not scheduled' do - let(:project) { create(:project, import_type: 'jira') } - let(:import_state) { create(:import_state, project: project, status: :none, jid: jid) } - it 'exits because import not started' do expect(Gitlab::JiraImport::Stage::ImportLabelsWorker).not_to receive(:perform_async) @@ -46,32 +40,21 @@ describe Gitlab::JiraImport::Stage::StartImportWorker do end context 'when import is scheduled' do - let(:import_state) { create(:import_state, status: :scheduled, jid: jid) } - let(:project) { create(:project, import_type: 'jira', import_state: import_state) } - - context 'when this is a mirror sync in a jira imported project' do - it 'exits early' do - expect(Gitlab::Import::SetAsyncJid).not_to receive(:set_jid) - expect(Gitlab::JiraImport::Stage::ImportLabelsWorker).not_to receive(:perform_async) - - worker.perform(project.id) - end + before do + jira_import.schedule! end - context 'when scheduled import is a hard triggered jira import and not a mirror' do - let!(:project) { create(:project, import_type: 'jira', import_data: import_data, import_state: import_state) } - - it 'advances to importing labels' do - expect(Gitlab::JiraImport::Stage::ImportLabelsWorker).to receive(:perform_async) + it 'advances to importing labels' do + expect(Gitlab::JiraImport::Stage::ImportLabelsWorker).to receive(:perform_async) - worker.perform(project.id) - end + worker.perform(project.id) end end context 'when import is started' do - let!(:import_state) { create(:import_state, status: :started, jid: jid) } - let!(:project) { create(:project, import_type: 'jira', import_data: import_data, import_state: import_state) } + before do + jira_import.update!(status: :started) + end context 'when this is the same worker that stated import' do it 'advances to importing labels' do @@ -93,8 +76,9 @@ describe Gitlab::JiraImport::Stage::StartImportWorker do end context 'when import is finished' do - let!(:import_state) { create(:import_state, status: :finished, jid: jid) } - let!(:project) { create(:project, import_type: 'jira', import_data: import_data, import_state: import_state) } + before do + jira_import.update!(status: :finished) + end it 'advances to importing labels' do allow(worker).to receive(:jid).and_return(jid) |