summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2017-04-24 15:17:02 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2017-04-24 15:17:02 +0000
commite2ff940685784760534294d7af658ff5d88103d3 (patch)
tree65c634da1e7fbcf5c3d988f4b875759f5778b8e9
parent0affdb85b1c84d2664da634b5dea86c1be5e8c6a (diff)
parent103684b779d64d8d3e8aecb22314eec460858847 (diff)
downloadgitlab-ce-e2ff940685784760534294d7af658ff5d88103d3.tar.gz
Merge branch 'fix/gb/fix-blocked-pipeline-duration' into 'master'
Fix missing duration for blocked pipelines Closes #31264 See merge request !10856
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--changelogs/unreleased/fix-gb-fix-blocked-pipeline-duration.yml4
-rw-r--r--spec/models/ci/pipeline_spec.rb65
3 files changed, 53 insertions, 20 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 445247f1b41..75a8ab2f5cd 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -75,6 +75,10 @@ module Ci
pipeline.update_duration
end
+ before_transition any => [:manual] do |pipeline|
+ pipeline.update_duration
+ end
+
before_transition canceled: any - [:canceled] do |pipeline|
pipeline.auto_canceled_by = nil
end
diff --git a/changelogs/unreleased/fix-gb-fix-blocked-pipeline-duration.yml b/changelogs/unreleased/fix-gb-fix-blocked-pipeline-duration.yml
new file mode 100644
index 00000000000..5c87b1fdbd5
--- /dev/null
+++ b/changelogs/unreleased/fix-gb-fix-blocked-pipeline-duration.yml
@@ -0,0 +1,4 @@
+---
+title: Fix missing duration for blocked pipelines
+merge_request: 10856
+author:
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index d7d6a75d38d..675be77eafd 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_build('manual:action', :manual) }
- 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)
- create(:ci_build,
+ def create_build(name, *traits, queued_at: current, started_from: 0, **opts)
+ create(:ci_build, *traits,
name: name,
pipeline: pipeline,
queued_at: queued_at,
- started_at: queued_at + started_from)
+ started_at: queued_at + started_from,
+ **opts)
end
end