summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-09-13 16:14:20 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-09-13 16:14:20 +0800
commit18d7ae43099040d21dddbb114761c34c833ec766 (patch)
tree6a6f56fd5c0312a7b95255e1fedb26efa8eec6f7
parentddcb8c880cbeb27a10e36fe1acb1e46963c3a377 (diff)
downloadgitlab-ce-18d7ae43099040d21dddbb114761c34c833ec766.tar.gz
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.
-rw-r--r--spec/models/ci/pipeline_spec.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index fbf945c757c..5d9063c0bc5 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -373,8 +373,8 @@ describe Ci::Pipeline, models: true do
end
describe '#execute_hooks' do
- let!(:build_a) { create_build('a') }
- let!(:build_b) { create_build('b') }
+ let!(:build_a) { create_build('a', 0) }
+ let!(:build_b) { create_build('b', 1) }
let!(:hook) do
create(:project_hook, project: project, pipeline_events: enabled)
@@ -427,6 +427,16 @@ describe Ci::Pipeline, models: true do
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)
have_requested(:post, hook.url).with do |req|
json_body = JSON.parse(req.body)
@@ -450,8 +460,12 @@ describe Ci::Pipeline, models: true do
end
end
- def create_build(name)
- create(:ci_build, :created, pipeline: pipeline, name: name)
+ def create_build(name, stage_idx)
+ create(:ci_build,
+ :created,
+ pipeline: pipeline,
+ name: name,
+ stage_idx: stage_idx)
end
end
end