2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-18 09:52:57 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-08-25 02:55:32 +00:00
|
|
|
describe HasStatus do
|
2019-10-01 12:05:59 +00:00
|
|
|
describe '.slow_composite_status' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
subject { CommitStatus.slow_composite_status }
|
2016-08-25 02:55:32 +00:00
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
shared_examples 'build status summary' do
|
|
|
|
context 'all successful' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) { Array.new(2) { create(type, status: :success) } }
|
2019-10-01 12:05:59 +00:00
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
it { is_expected.to eq 'success' }
|
|
|
|
end
|
2016-02-18 09:52:57 +00:00
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
context 'at least one failed' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-02-20 15:35:29 +00:00
|
|
|
[create(type, status: :success), create(type, status: :failed)]
|
2016-02-19 18:58:43 +00:00
|
|
|
end
|
2016-02-18 10:47:35 +00:00
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
it { is_expected.to eq 'failed' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'at least one running' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-02-20 15:35:29 +00:00
|
|
|
[create(type, status: :success), create(type, status: :running)]
|
2016-02-19 18:58:43 +00:00
|
|
|
end
|
2016-02-18 10:47:35 +00:00
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
it { is_expected.to eq 'running' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'at least one pending' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-02-20 15:35:29 +00:00
|
|
|
[create(type, status: :success), create(type, status: :pending)]
|
2016-02-19 18:58:43 +00:00
|
|
|
end
|
2016-02-18 10:47:35 +00:00
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
it { is_expected.to eq 'running' }
|
|
|
|
end
|
|
|
|
|
2019-12-24 12:08:01 +00:00
|
|
|
context 'all waiting for resource' do
|
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :waiting_for_resource), create(type, status: :waiting_for_resource)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'waiting_for_resource' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'at least one waiting for resource' do
|
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :success), create(type, status: :waiting_for_resource)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'waiting_for_resource' }
|
|
|
|
end
|
|
|
|
|
2019-02-27 02:13:06 +00:00
|
|
|
context 'all preparing' do
|
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :preparing), create(type, status: :preparing)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'preparing' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'at least one preparing' do
|
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :success), create(type, status: :preparing)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'preparing' }
|
|
|
|
end
|
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
context 'success and failed but allowed to fail' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-02-20 15:35:29 +00:00
|
|
|
[create(type, status: :success),
|
|
|
|
create(type, status: :failed, allow_failure: true)]
|
2016-02-19 18:58:43 +00:00
|
|
|
end
|
2016-02-18 10:47:35 +00:00
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
it { is_expected.to eq 'success' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'one failed but allowed to fail' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :failed, allow_failure: true)]
|
|
|
|
end
|
|
|
|
|
2017-05-08 13:14:41 +00:00
|
|
|
it { is_expected.to eq 'success' }
|
2016-02-20 15:35:29 +00:00
|
|
|
end
|
|
|
|
|
2016-03-17 14:54:56 +00:00
|
|
|
context 'success and canceled' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-03-17 14:54:56 +00:00
|
|
|
[create(type, status: :success), create(type, status: :canceled)]
|
|
|
|
end
|
2016-04-18 07:44:22 +00:00
|
|
|
|
|
|
|
it { is_expected.to eq 'canceled' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'one failed and one canceled' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-04-18 07:44:22 +00:00
|
|
|
[create(type, status: :failed), create(type, status: :canceled)]
|
|
|
|
end
|
|
|
|
|
2016-03-17 14:54:56 +00:00
|
|
|
it { is_expected.to eq 'failed' }
|
2016-04-18 07:44:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'one failed but allowed to fail and one canceled' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-04-18 07:44:22 +00:00
|
|
|
[create(type, status: :failed, allow_failure: true),
|
|
|
|
create(type, status: :canceled)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'canceled' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'one running one canceled' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-04-18 07:44:22 +00:00
|
|
|
[create(type, status: :running), create(type, status: :canceled)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'running' }
|
2016-03-17 14:54:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'all canceled' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-03-17 14:54:56 +00:00
|
|
|
[create(type, status: :canceled), create(type, status: :canceled)]
|
|
|
|
end
|
2016-10-03 11:35:53 +00:00
|
|
|
|
2016-03-17 14:54:56 +00:00
|
|
|
it { is_expected.to eq 'canceled' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'success and canceled but allowed to fail' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-03-17 14:54:56 +00:00
|
|
|
[create(type, status: :success),
|
|
|
|
create(type, status: :canceled, allow_failure: true)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'success' }
|
|
|
|
end
|
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
context 'one finished and second running but allowed to fail' do
|
2016-10-03 11:35:53 +00:00
|
|
|
let!(:statuses) do
|
2016-02-20 15:35:29 +00:00
|
|
|
[create(type, status: :success),
|
|
|
|
create(type, status: :running, allow_failure: true)]
|
2016-02-19 18:58:43 +00:00
|
|
|
end
|
2016-02-20 15:35:29 +00:00
|
|
|
|
2017-03-20 18:16:48 +00:00
|
|
|
it { is_expected.to eq 'running' }
|
|
|
|
end
|
|
|
|
|
2017-03-20 19:28:37 +00:00
|
|
|
context 'when one status finished and second is still created' do
|
2017-03-20 18:16:48 +00:00
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :success), create(type, status: :created)]
|
|
|
|
end
|
|
|
|
|
2016-02-20 15:35:29 +00:00
|
|
|
it { is_expected.to eq 'running' }
|
2016-02-19 18:58:43 +00:00
|
|
|
end
|
2017-03-06 12:54:29 +00:00
|
|
|
|
2017-03-20 19:28:37 +00:00
|
|
|
context 'when there is a manual status before created status' do
|
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :success),
|
|
|
|
create(type, status: :manual, allow_failure: false),
|
|
|
|
create(type, status: :created)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'manual' }
|
|
|
|
end
|
|
|
|
|
2017-03-06 12:54:29 +00:00
|
|
|
context 'when one status is a blocking manual action' do
|
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :failed),
|
|
|
|
create(type, status: :manual, allow_failure: false)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'manual' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when one status is a non-blocking manual action' do
|
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :failed),
|
|
|
|
create(type, status: :manual, allow_failure: true)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'failed' }
|
|
|
|
end
|
2016-02-18 10:47:35 +00:00
|
|
|
end
|
2016-02-20 15:35:29 +00:00
|
|
|
|
2019-10-01 12:05:59 +00:00
|
|
|
where(:ci_composite_status) do
|
|
|
|
[false, true]
|
2016-02-20 15:35:29 +00:00
|
|
|
end
|
|
|
|
|
2019-10-01 12:05:59 +00:00
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(ci_composite_status: ci_composite_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'ci build statuses' do
|
|
|
|
let(:type) { :ci_build }
|
2016-10-03 11:35:53 +00:00
|
|
|
|
2019-10-01 12:05:59 +00:00
|
|
|
it_behaves_like 'build status summary'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'generic commit statuses' do
|
|
|
|
let(:type) { :generic_commit_status }
|
|
|
|
|
|
|
|
it_behaves_like 'build status summary'
|
|
|
|
end
|
2016-02-20 15:35:29 +00:00
|
|
|
end
|
2016-02-18 09:52:57 +00:00
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
|
|
|
|
context 'for scope with one status' do
|
2016-11-21 14:39:58 +00:00
|
|
|
shared_examples 'having a job' do |status|
|
|
|
|
%i[ci_build generic_commit_status].each do |type|
|
|
|
|
context "when it's #{status} #{type} job" do
|
|
|
|
let!(:job) { create(type, status) }
|
2016-11-18 17:02:49 +00:00
|
|
|
|
2016-11-21 14:39:58 +00:00
|
|
|
describe ".#{status}" do
|
|
|
|
it 'contains the job' do
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(CommitStatus.public_send(status).all)
|
|
|
|
.to contain_exactly(job)
|
2016-11-21 14:39:58 +00:00
|
|
|
end
|
2016-11-21 09:59:57 +00:00
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
|
2016-11-21 14:39:58 +00:00
|
|
|
describe '.relevant' do
|
|
|
|
if status == :created
|
|
|
|
it 'contains nothing' do
|
|
|
|
expect(CommitStatus.relevant.all).to be_empty
|
|
|
|
end
|
|
|
|
else
|
|
|
|
it 'contains the job' do
|
|
|
|
expect(CommitStatus.relevant.all).to contain_exactly(job)
|
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-24 12:08:01 +00:00
|
|
|
%i[created waiting_for_resource preparing running pending success
|
2016-11-18 17:02:49 +00:00
|
|
|
failed canceled skipped].each do |status|
|
2016-11-21 14:39:58 +00:00
|
|
|
it_behaves_like 'having a job', status
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for scope with more statuses' do
|
2016-11-21 14:39:58 +00:00
|
|
|
shared_examples 'containing the job' do |status|
|
|
|
|
%i[ci_build generic_commit_status].each do |type|
|
|
|
|
context "when it's #{status} #{type} job" do
|
|
|
|
let!(:job) { create(type, status) }
|
2016-11-18 17:02:49 +00:00
|
|
|
|
2016-11-21 14:39:58 +00:00
|
|
|
it 'contains the job' do
|
|
|
|
is_expected.to contain_exactly(job)
|
|
|
|
end
|
2016-11-21 09:59:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-21 14:39:58 +00:00
|
|
|
shared_examples 'not containing the job' do |status|
|
|
|
|
%i[ci_build generic_commit_status].each do |type|
|
|
|
|
context "when it's #{status} #{type} job" do
|
|
|
|
let!(:job) { create(type, status) }
|
2016-11-21 09:59:57 +00:00
|
|
|
|
2016-11-21 14:39:58 +00:00
|
|
|
it 'contains nothing' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.running_or_pending' do
|
|
|
|
subject { CommitStatus.running_or_pending }
|
|
|
|
|
2016-11-21 09:59:57 +00:00
|
|
|
%i[running pending].each do |status|
|
2016-11-21 14:39:58 +00:00
|
|
|
it_behaves_like 'containing the job', status
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
2016-11-21 09:59:57 +00:00
|
|
|
|
2016-11-21 14:39:58 +00:00
|
|
|
%i[created failed success].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
|
|
|
|
2017-09-28 10:57:16 +00:00
|
|
|
describe '.alive' do
|
|
|
|
subject { CommitStatus.alive }
|
|
|
|
|
2019-12-24 12:08:01 +00:00
|
|
|
%i[running pending waiting_for_resource preparing created].each do |status|
|
2017-09-28 10:57:16 +00:00
|
|
|
it_behaves_like 'containing the job', status
|
|
|
|
end
|
|
|
|
|
|
|
|
%i[failed success].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-05 14:50:39 +00:00
|
|
|
describe '.alive_or_scheduled' do
|
|
|
|
subject { CommitStatus.alive_or_scheduled }
|
|
|
|
|
2019-12-24 12:08:01 +00:00
|
|
|
%i[running pending waiting_for_resource preparing created scheduled].each do |status|
|
2019-09-05 14:50:39 +00:00
|
|
|
it_behaves_like 'containing the job', status
|
|
|
|
end
|
|
|
|
|
|
|
|
%i[failed success canceled skipped].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-05 18:21:31 +00:00
|
|
|
describe '.created_or_pending' do
|
|
|
|
subject { CommitStatus.created_or_pending }
|
|
|
|
|
|
|
|
%i[created pending].each do |status|
|
|
|
|
it_behaves_like 'containing the job', status
|
|
|
|
end
|
|
|
|
|
|
|
|
%i[running failed success].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-18 17:02:49 +00:00
|
|
|
describe '.finished' do
|
|
|
|
subject { CommitStatus.finished }
|
|
|
|
|
2016-11-21 09:59:57 +00:00
|
|
|
%i[success failed canceled].each do |status|
|
2016-11-21 14:39:58 +00:00
|
|
|
it_behaves_like 'containing the job', status
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
2016-11-21 09:59:57 +00:00
|
|
|
|
2016-11-21 14:39:58 +00:00
|
|
|
%i[created running pending].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.cancelable' do
|
|
|
|
subject { CommitStatus.cancelable }
|
|
|
|
|
2019-12-24 12:08:01 +00:00
|
|
|
%i[running pending waiting_for_resource preparing created scheduled].each do |status|
|
2016-11-21 14:39:58 +00:00
|
|
|
it_behaves_like 'containing the job', status
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
2016-11-21 09:59:57 +00:00
|
|
|
|
2018-09-26 11:21:36 +00:00
|
|
|
%i[failed success skipped canceled manual].each do |status|
|
2016-11-21 14:39:58 +00:00
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
2017-03-06 12:54:29 +00:00
|
|
|
|
|
|
|
describe '.manual' do
|
|
|
|
subject { CommitStatus.manual }
|
|
|
|
|
|
|
|
%i[manual].each do |status|
|
|
|
|
it_behaves_like 'containing the job', status
|
|
|
|
end
|
|
|
|
|
|
|
|
%i[failed success skipped canceled].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
|
|
|
end
|
2018-09-26 11:21:36 +00:00
|
|
|
|
|
|
|
describe '.scheduled' do
|
|
|
|
subject { CommitStatus.scheduled }
|
|
|
|
|
|
|
|
%i[scheduled].each do |status|
|
|
|
|
it_behaves_like 'containing the job', status
|
|
|
|
end
|
|
|
|
|
|
|
|
%i[failed success skipped canceled].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
|
|
|
end
|
2016-11-18 17:02:49 +00:00
|
|
|
end
|
2017-01-18 10:34:55 +00:00
|
|
|
|
|
|
|
describe '::DEFAULT_STATUS' do
|
|
|
|
it 'is a status created' do
|
|
|
|
expect(described_class::DEFAULT_STATUS).to eq 'created'
|
|
|
|
end
|
|
|
|
end
|
2017-03-06 12:54:29 +00:00
|
|
|
|
|
|
|
describe '::BLOCKED_STATUS' do
|
|
|
|
it 'is a status manual' do
|
2018-09-24 04:12:11 +00:00
|
|
|
expect(described_class::BLOCKED_STATUS).to eq %w[manual scheduled]
|
2017-03-06 12:54:29 +00:00
|
|
|
end
|
|
|
|
end
|
2018-09-26 11:21:36 +00:00
|
|
|
|
|
|
|
describe 'blocked?' do
|
|
|
|
subject { object.blocked? }
|
|
|
|
|
|
|
|
%w[ci_pipeline ci_stage ci_build generic_commit_status].each do |type|
|
|
|
|
let(:object) { build(type, status: status) }
|
|
|
|
|
|
|
|
context 'when status is scheduled' do
|
|
|
|
let(:status) { :scheduled }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when status is manual' do
|
|
|
|
let(:status) { :manual }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when status is created' do
|
|
|
|
let(:status) { :created }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-01 12:05:59 +00:00
|
|
|
describe '.legacy_status_sql' do
|
|
|
|
subject { Ci::Build.legacy_status_sql }
|
2018-09-26 11:21:36 +00:00
|
|
|
|
|
|
|
it 'returns SQL' do
|
|
|
|
puts subject
|
|
|
|
end
|
|
|
|
end
|
2016-02-18 09:52:57 +00:00
|
|
|
end
|