2019-03-30 03:15:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-14 06:53:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe BuildFinishedWorker do
|
2021-10-11 05:09:08 -04:00
|
|
|
let(:worker) { described_class.new }
|
|
|
|
|
|
|
|
subject { worker.perform(build.id) }
|
2020-06-02 17:08:00 -04:00
|
|
|
|
2016-10-14 06:53:51 -04:00
|
|
|
describe '#perform' do
|
|
|
|
context 'when build exists' do
|
2021-04-01 17:09:22 -04:00
|
|
|
let_it_be(:build) { create(:ci_build, :success, pipeline: create(:ci_pipeline)) }
|
2016-10-14 06:53:51 -04:00
|
|
|
|
2021-02-05 10:09:28 -05:00
|
|
|
before do
|
2022-05-02 11:10:10 -04:00
|
|
|
expect(Ci::Build).to receive(:find_by).with({ id: build.id }).and_return(build)
|
2021-02-05 10:09:28 -05:00
|
|
|
end
|
2020-10-23 14:08:31 -04:00
|
|
|
|
2021-02-05 10:09:28 -05:00
|
|
|
it 'calculates coverage and calls hooks', :aggregate_failures do
|
|
|
|
expect(build).to receive(:update_coverage).ordered
|
2020-10-23 14:08:31 -04:00
|
|
|
|
2021-02-05 10:09:28 -05:00
|
|
|
expect_next_instance_of(Ci::BuildReportResultService) do |build_report_result_service|
|
|
|
|
expect(build_report_result_service).to receive(:execute).with(build)
|
2020-10-23 14:08:31 -04:00
|
|
|
end
|
|
|
|
|
2018-02-05 11:52:46 -05:00
|
|
|
expect(BuildHooksWorker).to receive(:perform_async)
|
2020-06-02 17:08:00 -04:00
|
|
|
expect(ChatNotificationWorker).not_to receive(:perform_async)
|
2021-07-13 11:08:38 -04:00
|
|
|
expect(Ci::ArchiveTraceWorker).to receive(:perform_in)
|
2016-10-14 06:53:51 -04:00
|
|
|
|
2020-06-02 17:08:00 -04:00
|
|
|
subject
|
2016-10-14 06:53:51 -04:00
|
|
|
end
|
2021-04-01 17:09:22 -04:00
|
|
|
|
|
|
|
context 'when build is failed' do
|
|
|
|
before do
|
|
|
|
build.update!(status: :failed)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds a todo' do
|
|
|
|
expect(::Ci::MergeRequests::AddTodoWhenBuildFailsWorker).to receive(:perform_async)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build has a chat' do
|
|
|
|
before do
|
|
|
|
build.pipeline.update!(source: :chat)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules a ChatNotification job' do
|
|
|
|
expect(ChatNotificationWorker).to receive(:perform_async).with(build.id)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
2021-10-11 05:09:08 -04:00
|
|
|
|
|
|
|
context 'when project is deleted' do
|
|
|
|
before do
|
|
|
|
allow(build).to receive(:project).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does no processing' do
|
|
|
|
expect(worker).not_to receive(:process_build)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is pending_delete' do
|
|
|
|
before do
|
|
|
|
build.project.update_attribute(:pending_delete, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does no processing' do
|
|
|
|
expect(worker).not_to receive(:process_build)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
2016-10-14 06:53:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build does not exist' do
|
|
|
|
it 'does not raise exception' do
|
2020-10-23 14:08:31 -04:00
|
|
|
expect { described_class.new.perform(non_existing_record_id) }
|
2016-10-14 06:53:51 -04:00
|
|
|
.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|