Commit 031b1623 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Fix test for Pipeline#duration

parent 7e32e2ef
...@@ -124,17 +124,22 @@ describe Ci::Pipeline, models: true do ...@@ -124,17 +124,22 @@ describe Ci::Pipeline, models: true do
describe 'state machine' do describe 'state machine' do
let(:current) { Time.now.change(usec: 0) } let(:current) { Time.now.change(usec: 0) }
let(:build) { create :ci_build, name: 'build1', pipeline: pipeline } let(:build) { create_build('build1', current - 60) }
let(:another_build) { create_build('build2', current + 20) }
describe '#duration' do describe '#duration' do
before do before do
travel_to(current - 120) do pipeline.run
pipeline.run
end
travel_to(current) do travel_to(current) do
pipeline.succeed build.success
end
travel_to(current + 80) do
another_build.drop
end end
pipeline.drop
end end
it 'matches sum of builds duration' do it 'matches sum of builds duration' do
...@@ -169,6 +174,13 @@ describe Ci::Pipeline, models: true do ...@@ -169,6 +174,13 @@ describe Ci::Pipeline, models: true do
expect(pipeline.reload.finished_at).to be_nil expect(pipeline.reload.finished_at).to be_nil
end end
end end
def create_build(name, started_at = current)
create(:ci_build,
name: name,
pipeline: pipeline,
started_at: started_at)
end
end end
describe '#branch?' do describe '#branch?' do
......
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