Commit 3fdba5c9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix missing pipeline duration for blocked pipelines

parent 9c35162f
......@@ -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
......
......@@ -296,11 +296,12 @@ 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
context 'when multiple builds are finished' do
before do
travel_to(current + 30) do
build.run!
......@@ -325,6 +326,29 @@ describe Ci::Pipeline, models: true do
end
end
context 'when pipeline becomes blocked' do
let!(:build) { create_build('build:1') }
let!(:action) { create(:ci_build, :manual, pipeline: pipeline) }
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
describe '#started_at' do
it 'updates on transitioning to running' do
build.run
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment