summaryrefslogtreecommitdiff
path: root/spec/models/commit_status_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
commit9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch)
tree70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/models/commit_status_spec.rb
parent4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff)
downloadgitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/models/commit_status_spec.rb')
-rw-r--r--spec/models/commit_status_spec.rb118
1 files changed, 51 insertions, 67 deletions
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index 01da379e001..e64dee2d26f 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -213,12 +213,12 @@ RSpec.describe CommitStatus do
context 'when it is canceled' do
before do
- commit_status.update(status: 'canceled')
+ commit_status.update!(status: 'canceled')
end
context 'when there is auto_canceled_by' do
before do
- commit_status.update(auto_canceled_by: create(:ci_empty_pipeline))
+ commit_status.update!(auto_canceled_by: create(:ci_empty_pipeline))
end
it 'is auto canceled' do
@@ -510,10 +510,6 @@ RSpec.describe CommitStatus do
end
describe '#group_name' do
- before do
- stub_feature_flags(simplified_commit_status_group_name: false)
- end
-
using RSpec::Parameterized::TableSyntax
let(:commit_status) do
@@ -528,18 +524,24 @@ RSpec.describe CommitStatus do
'rspec1 0/2' | 'rspec1'
'rspec:windows' | 'rspec:windows'
'rspec:windows 0' | 'rspec:windows 0'
+ 'rspec:windows 0 2/2' | 'rspec:windows 0'
'rspec:windows 0 test' | 'rspec:windows 0 test'
- 'rspec:windows 0 1' | 'rspec:windows'
- 'rspec:windows 0 1 name' | 'rspec:windows name'
+ 'rspec:windows 0 test 2/2' | 'rspec:windows 0 test'
+ 'rspec:windows 0 1 2/2' | 'rspec:windows'
+ 'rspec:windows 0 1 [aws] 2/2' | 'rspec:windows'
+ 'rspec:windows 0 1 name [aws] 2/2' | 'rspec:windows 0 1 name'
+ 'rspec:windows 0 1 name' | 'rspec:windows 0 1 name'
+ 'rspec:windows 0 1 name 1/2' | 'rspec:windows 0 1 name'
'rspec:windows 0/1' | 'rspec:windows'
- 'rspec:windows 0/1 name' | 'rspec:windows name'
+ 'rspec:windows 0/1 name' | 'rspec:windows 0/1 name'
+ 'rspec:windows 0/1 name 1/2' | 'rspec:windows 0/1 name'
'rspec:windows 0:1' | 'rspec:windows'
- 'rspec:windows 0:1 name' | 'rspec:windows name'
+ 'rspec:windows 0:1 name' | 'rspec:windows 0:1 name'
'rspec:windows 10000 20000' | 'rspec:windows'
'rspec:windows 0 : / 1' | 'rspec:windows'
- 'rspec:windows 0 : / 1 name' | 'rspec:windows name'
- '0 1 name ruby' | 'name ruby'
- '0 :/ 1 name ruby' | 'name ruby'
+ 'rspec:windows 0 : / 1 name' | 'rspec:windows 0 : / 1 name'
+ '0 1 name ruby' | '0 1 name ruby'
+ '0 :/ 1 name ruby' | '0 :/ 1 name ruby'
'rspec: [aws]' | 'rspec'
'rspec: [aws] 0/1' | 'rspec'
'rspec: [aws, max memory]' | 'rspec'
@@ -561,58 +563,6 @@ RSpec.describe CommitStatus do
is_expected.to eq(group_name)
end
end
-
- context 'with simplified_commit_status_group_name' do
- before do
- stub_feature_flags(simplified_commit_status_group_name: true)
- end
-
- where(:name, :group_name) do
- 'rspec1' | 'rspec1'
- 'rspec1 0 1' | 'rspec1'
- 'rspec1 0/2' | 'rspec1'
- 'rspec:windows' | 'rspec:windows'
- 'rspec:windows 0' | 'rspec:windows 0'
- 'rspec:windows 0 2/2' | 'rspec:windows 0'
- 'rspec:windows 0 test' | 'rspec:windows 0 test'
- 'rspec:windows 0 test 2/2' | 'rspec:windows 0 test'
- 'rspec:windows 0 1 2/2' | 'rspec:windows'
- 'rspec:windows 0 1 [aws] 2/2' | 'rspec:windows'
- 'rspec:windows 0 1 name [aws] 2/2' | 'rspec:windows 0 1 name'
- 'rspec:windows 0 1 name' | 'rspec:windows 0 1 name'
- 'rspec:windows 0 1 name 1/2' | 'rspec:windows 0 1 name'
- 'rspec:windows 0/1' | 'rspec:windows'
- 'rspec:windows 0/1 name' | 'rspec:windows 0/1 name'
- 'rspec:windows 0/1 name 1/2' | 'rspec:windows 0/1 name'
- 'rspec:windows 0:1' | 'rspec:windows'
- 'rspec:windows 0:1 name' | 'rspec:windows 0:1 name'
- 'rspec:windows 10000 20000' | 'rspec:windows'
- 'rspec:windows 0 : / 1' | 'rspec:windows'
- 'rspec:windows 0 : / 1 name' | 'rspec:windows 0 : / 1 name'
- '0 1 name ruby' | '0 1 name ruby'
- '0 :/ 1 name ruby' | '0 :/ 1 name ruby'
- 'rspec: [aws]' | 'rspec'
- 'rspec: [aws] 0/1' | 'rspec'
- 'rspec: [aws, max memory]' | 'rspec'
- 'rspec:linux: [aws, max memory, data]' | 'rspec:linux'
- 'rspec: [inception: [something, other thing], value]' | 'rspec'
- 'rspec:windows 0/1: [name, other]' | 'rspec:windows'
- 'rspec:windows: [name, other] 0/1' | 'rspec:windows'
- 'rspec:windows: [name, 0/1] 0/1' | 'rspec:windows'
- 'rspec:windows: [0/1, name]' | 'rspec:windows'
- 'rspec:windows: [, ]' | 'rspec:windows'
- 'rspec:windows: [name]' | 'rspec:windows'
- 'rspec:windows: [name,other]' | 'rspec:windows'
- end
-
- with_them do
- it "#{params[:name]} puts in #{params[:group_name]}" do
- commit_status.name = name
-
- is_expected.to eq(group_name)
- end
- end
- end
end
describe '#detailed_status' do
@@ -660,7 +610,7 @@ RSpec.describe CommitStatus do
end
it "raise exception when trying to update" do
- expect { commit_status.save }.to raise_error(ActiveRecord::StaleObjectError)
+ expect { commit_status.save! }.to raise_error(ActiveRecord::StaleObjectError)
end
end
@@ -679,30 +629,45 @@ RSpec.describe CommitStatus do
end
end
- describe 'set failure_reason when drop' do
+ describe '#drop' do
let(:commit_status) { create(:commit_status, :created) }
+ let(:counter) { Gitlab::Metrics.counter(:gitlab_ci_job_failure_reasons, 'desc') }
+ let(:failure_reason) { reason.to_s }
subject do
commit_status.drop!(reason)
commit_status
end
+ shared_examples 'incrementing failure reason counter' do
+ it 'increments the counter with the failure_reason' do
+ expect { subject }.to change { counter.get(reason: failure_reason) }.by(1)
+ end
+ end
+
context 'when failure_reason is nil' do
let(:reason) { }
+ let(:failure_reason) { 'unknown_failure' }
it { is_expected.to be_unknown_failure }
+
+ it_behaves_like 'incrementing failure reason counter'
end
context 'when failure_reason is script_failure' do
let(:reason) { :script_failure }
it { is_expected.to be_script_failure }
+
+ it_behaves_like 'incrementing failure reason counter'
end
context 'when failure_reason is unmet_prerequisites' do
let(:reason) { :unmet_prerequisites }
it { is_expected.to be_unmet_prerequisites }
+
+ it_behaves_like 'incrementing failure reason counter'
end
end
@@ -870,4 +835,23 @@ RSpec.describe CommitStatus do
it { is_expected.to eq(false) }
end
end
+
+ describe '#update_older_statuses_retried!' do
+ let!(:build_old) { create_status(name: 'build') }
+ let!(:build_new) { create_status(name: 'build') }
+ let!(:test) { create_status(name: 'test') }
+ let!(:build_from_other_pipeline) do
+ new_pipeline = create(:ci_pipeline, project: project, sha: project.commit.id)
+ create_status(name: 'build', pipeline: new_pipeline)
+ end
+
+ it "updates 'retried' and 'status' columns of the latest status with the same name in the same pipeline" do
+ build_new.update_older_statuses_retried!
+
+ expect(build_new.reload).to have_attributes(retried: false, processed: false)
+ expect(build_old.reload).to have_attributes(retried: true, processed: true)
+ expect(test.reload).to have_attributes(retried: false, processed: false)
+ expect(build_from_other_pipeline.reload).to have_attributes(retried: false, processed: false)
+ end
+ end
end