diff options
author | Markus Doits <markus.doits@stellenticket.de> | 2018-09-15 14:02:43 +0200 |
---|---|---|
committer | Markus Doits <markus.doits@stellenticket.de> | 2018-11-07 13:00:39 +0100 |
commit | 007db85dd4e4c92e060160427429c4fb2ad5cb32 (patch) | |
tree | cfa5202a504dcb7a944556bb5c286997d82d280e /spec/models/ci | |
parent | 473b52b2837bfffc634f574f148d949e218137ed (diff) | |
download | gitlab-ce-007db85dd4e4c92e060160427429c4fb2ad5cb32.tar.gz |
add `retry_failure?` option and use it to decide if to retry a build failure
Diffstat (limited to 'spec/models/ci')
-rw-r--r-- | spec/models/ci/build_spec.rb | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index ba1de3612ad..3085cf7b271 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1538,6 +1538,156 @@ describe Ci::Build do end end end + + describe '#retry_failure?' do + subject { create(:ci_build) } + + context 'when retries max is zero' do + before do + expect(subject).to receive(:retries_max).at_least(:once).and_return(0) + end + + it 'returns false' do + expect(subject.retry_failure?).to eq false + end + end + + context 'when retries max equals retries count' do + before do + expect(subject).to receive(:retries_max).at_least(:once).and_return(1) + expect(subject).to receive(:retries_count).at_least(:once).and_return(1) + end + + it 'returns false' do + expect(subject.retry_failure?).to eq false + end + end + + context 'when retries max is higher than retries count' do + before do + expect(subject).to receive(:retries_max).at_least(:once).and_return(2) + expect(subject).to receive(:retries_count).at_least(:once).and_return(1) + end + + context 'and retry when is always' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('always') + end + + it 'returns true' do + expect(subject.retry_failure?).to eq true + end + end + + context 'and failure was a system runner failure' do + before do + expect(subject).to receive(:failure_reason).at_least(:once).and_return('runner_system_failure') + end + + context 'and retry when is always' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('always') + end + + it 'returns true' do + expect(subject.retry_failure?).to eq true + end + end + + context 'and retry when is system failure' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('system failure') + end + + it 'returns true' do + expect(subject.retry_failure?).to eq true + end + end + + context 'and retry when is script failure' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('script failure') + end + + it 'returns false' do + expect(subject.retry_failure?).to eq false + end + end + end + + context 'and failure was a script failure' do + before do + expect(subject).to receive(:failure_reason).at_least(:once).and_return('script_failure') + end + + context 'and retry when is always' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('always') + end + + it 'returns true' do + expect(subject.retry_failure?).to eq true + end + end + + context 'and retry when is system failure' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('system failure') + end + + it 'returns false' do + expect(subject.retry_failure?).to eq false + end + end + + context 'and retry when is script failure' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('script failure') + end + + it 'returns true' do + expect(subject.retry_failure?).to eq true + end + end + end + + context 'and failure was some other failure' do + before do + expect(subject).to receive(:failure_reason).at_least(:once).and_return('some other reason') + end + + context 'and retry when is always' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('always') + end + + it 'returns true' do + expect(subject.retry_failure?).to eq true + end + end + + context 'and retry when is system failure' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('system failure') + end + + it 'returns false' do + expect(subject.retry_failure?).to eq false + end + end + + context 'and retry when is script failure' do + before do + expect(subject).to receive(:retry_when).at_least(:once).and_return('script failure') + end + + it 'returns false' do + expect(subject.retry_failure?).to eq false + end + end + end + end + end end describe '#keep_artifacts!' do |