BigW Consortium Gitlab

Commit 18d7ae43 by Lin Jen-Shin

Add a test for #22010

The observed faulty state transition is probably hard to test, because we need to hook into internal states to observe them. Namely this: 07:30:16 | Build#ruby-2.2 enqueue: created -> pending 07:30:16 | Pipeline#32 enqueue: created -> pending 07:30:16 | Build#ruby-2.3 enqueue: created -> pending 07:30:16 | Build#ruby-2.2 run: pending -> running 07:30:16 | Pipeline#32 run: pending -> running 07:30:29 | Build#ruby-2.2 drop: running -> failed 07:30:29 | Pipeline#32 run: running -> running 07:30:29 | Build#ruby-2.3 run: pending -> running 07:30:30 | Pipeline#32 run: running -> running 07:30:57 | Build#gem:build skip: created -> skipped 07:30:57 | Pipeline#32 drop: running -> failed 07:30:57 | Build#gem:release skip: created -> skipped 07:30:57 | Pipeline#32 drop: failed -> failed 07:30:57 | Build#ruby-2.3 drop: running -> failed 07:30:57 | Pipeline#32 drop: running -> failed ^^^ Should be failed -> failed However, the consequence of this, executing hooks twice would be easy enough to observe. So we could at least test against this. Keep in mind that if we ever changed how we execute the hooks this won't be testing against faulty state transition.
parent ddcb8c88
...@@ -373,8 +373,8 @@ describe Ci::Pipeline, models: true do ...@@ -373,8 +373,8 @@ describe Ci::Pipeline, models: true do
end end
describe '#execute_hooks' do describe '#execute_hooks' do
let!(:build_a) { create_build('a') } let!(:build_a) { create_build('a', 0) }
let!(:build_b) { create_build('b') } let!(:build_b) { create_build('b', 1) }
let!(:hook) do let!(:hook) do
create(:project_hook, project: project, pipeline_events: enabled) create(:project_hook, project: project, pipeline_events: enabled)
...@@ -427,6 +427,16 @@ describe Ci::Pipeline, models: true do ...@@ -427,6 +427,16 @@ describe Ci::Pipeline, models: true do
end end
end end
context 'when stage one failed' do
before do
build_a.drop
end
it 'receive a failed event once' do
expect(WebMock).to have_requested_pipeline_hook('failed').once
end
end
def have_requested_pipeline_hook(status) def have_requested_pipeline_hook(status)
have_requested(:post, hook.url).with do |req| have_requested(:post, hook.url).with do |req|
json_body = JSON.parse(req.body) json_body = JSON.parse(req.body)
...@@ -450,8 +460,12 @@ describe Ci::Pipeline, models: true do ...@@ -450,8 +460,12 @@ describe Ci::Pipeline, models: true do
end end
end end
def create_build(name) def create_build(name, stage_idx)
create(:ci_build, :created, pipeline: pipeline, name: name) create(:ci_build,
:created,
pipeline: pipeline,
name: name,
stage_idx: stage_idx)
end end
end end
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