diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-21 19:45:14 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-21 19:45:14 +0200 |
commit | 3fdba5c96bcc3ccc8623f007127c530b1472b10f (patch) | |
tree | cd78593a357074adbef5e2a6a885c33a475d906e /spec | |
parent | 9c35162f83fb62349b922baaf192038522b09793 (diff) | |
download | gitlab-ce-3fdba5c96bcc3ccc8623f007127c530b1472b10f.tar.gz |
Fix missing pipeline duration for blocked pipelines
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index d7d6a75d38d..edefd258c06 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -296,32 +296,56 @@ describe Ci::Pipeline, models: true do describe 'state machine' do let(:current) { Time.now.change(usec: 0) } - let(:build) { create_build('build1', 0) } - let(:build_b) { create_build('build2', 0) } - let(:build_c) { create_build('build3', 0) } + let(:build) { create_build('build1', queued_at: 0) } + let(:build_b) { create_build('build2', queued_at: 0) } + let(:build_c) { create_build('build3', queued_at: 0) } describe '#duration' do - before do - travel_to(current + 30) do - build.run! - build.success! - build_b.run! - build_c.run! - end + context 'when multiple builds are finished' do + before do + travel_to(current + 30) do + build.run! + build.success! + build_b.run! + build_c.run! + end - travel_to(current + 40) do - build_b.drop! + travel_to(current + 40) do + build_b.drop! + end + + travel_to(current + 70) do + build_c.success! + end end - travel_to(current + 70) do - build_c.success! + it 'matches sum of builds duration' do + pipeline.reload + + expect(pipeline.duration).to eq(40) end end - it 'matches sum of builds duration' do - pipeline.reload + context 'when pipeline becomes blocked' do + let!(:build) { create_build('build:1') } + let!(:action) { create(:ci_build, :manual, pipeline: pipeline) } - expect(pipeline.duration).to eq(40) + before do + travel_to(current + 1.minute) do + build.run! + end + + travel_to(current + 5.minutes) do + build.success! + end + end + + it 'recalculates pipeline duration' do + pipeline.reload + + expect(pipeline).to be_manual + expect(pipeline.duration).to eq 4.minutes + end end end @@ -383,12 +407,13 @@ describe Ci::Pipeline, models: true do end end - def create_build(name, queued_at = current, started_from = 0) + def create_build(name, queued_at: current, started_from: 0, **opts) create(:ci_build, name: name, pipeline: pipeline, queued_at: queued_at, - started_at: queued_at + started_from) + started_at: queued_at + started_from, + **opts) end end |