Commit 93952e6d authored by Furkan Ayhan's avatar Furkan Ayhan

Implement new way to test ci process pipeline service

With this, we can easily write test cases
parent b379cb19
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
require 'spec_helper' require 'spec_helper'
require_relative 'shared_processing_service.rb' require_relative 'shared_processing_service.rb'
# require_relative 'shared_processing_service_tests_with_yaml.rb'
describe Ci::PipelineProcessing::AtomicProcessingService do describe Ci::PipelineProcessing::AtomicProcessingService do
before do before do
...@@ -9,6 +10,9 @@ describe Ci::PipelineProcessing::AtomicProcessingService do ...@@ -9,6 +10,9 @@ describe Ci::PipelineProcessing::AtomicProcessingService do
end end
it_behaves_like 'Pipeline Processing Service' it_behaves_like 'Pipeline Processing Service'
# TODO: This needs to be enabled. There is a different behavior when using `needs` depending on
# a `manual` job. More info: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/29405#note_327520605
# it_behaves_like 'Pipeline Processing Service Tests With Yaml'
private private
......
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
require 'spec_helper' require 'spec_helper'
require_relative 'shared_processing_service.rb' require_relative 'shared_processing_service.rb'
require_relative 'shared_processing_service_tests_with_yaml.rb'
describe Ci::PipelineProcessing::LegacyProcessingService do describe Ci::PipelineProcessing::LegacyProcessingService do
before do before do
stub_feature_flags(ci_atomic_processing: false) stub_feature_flags(ci_atomic_processing: false)
stub_feature_flags(ci_composite_status: false)
end end
it_behaves_like 'Pipeline Processing Service' it_behaves_like 'Pipeline Processing Service'
it_behaves_like 'Pipeline Processing Service Tests With Yaml'
private private
......
# frozen_string_literal: true
shared_context 'Pipeline Processing Service Tests With Yaml' do
where(:test_file_path) do
Dir.glob(Rails.root.join('spec/services/ci/pipeline_processing/test_cases/*.yml'))
end
with_them do
let(:test_file) { YAML.load_file(test_file_path) }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:pipeline) { Ci::CreatePipelineService.new(project, user, ref: 'master').execute(:pipeline) }
before do
stub_ci_pipeline_yaml_file(YAML.dump(test_file['config']))
stub_not_protect_default_branch
project.add_developer(user)
end
it 'follows transitions', :sidekiq_inline do
expect(pipeline).to be_persisted
check_expectation(test_file.dig('init', 'expect'))
test_file['transitions'].each do |transition|
event_on_jobs(transition['event'], transition['jobs'])
check_expectation(transition['expect'])
end
end
private
def check_expectation(expectation)
expectation.each do |key, value|
case key
when 'pipeline'
expect(pipeline.reload.status).to eq(value)
when 'stages'
expect(pipeline.stages.pluck(:name, :status).to_h).to eq(value)
when 'jobs'
expect(pipeline.builds.latest.pluck(:name, :status).to_h).to eq(value)
end
end
end
def event_on_jobs(event, job_names)
builds = pipeline.builds.latest.where(name: job_names).to_a
expect(builds.count).to eq(job_names.count) # ensure that we have the same counts
builds.each { |build| build.public_send("#{event}!") }
end
end
end
config:
build:
stage: build
allow_failure: true
script: exit 1
test:
stage: test
when: on_failure
script: exit 0
needs: [build]
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: success
stages:
build: success
test: skipped
deploy: skipped
jobs:
build: failed
test: skipped
deploy: skipped
# TODO: What is the real expected behavior here?
# Is `needs` keyword a requirement indicator or just a helper to build dependency tree?
# How should it behave `when: on_failure` with `needs`?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build:
stage: build
script: exit 1
test:
stage: test
script: exit 0
needs: [build]
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: failed
stages:
build: failed
test: skipped
deploy: skipped
jobs:
build: failed
test: skipped
deploy: skipped
config:
build:
stage: build
script: exit 1
test:
stage: test
script: exit 0
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: failed
stages:
build: failed
test: skipped
deploy: skipped
jobs:
build: failed
test: skipped
deploy: skipped
config:
build:
stage: build
script: exit 1
test:
stage: test
script: exit 0
deploy:
stage: deploy
script: exit 0
when: always
needs: [test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: running
stages:
build: failed
test: skipped
deploy: pending
jobs:
build: failed
test: skipped
deploy: pending
# TODO: `test` is actually skipped, but we run `deploy`. Should we?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build_1:
stage: build
script: exit 0
build_2:
stage: build
script: exit 1
test:
stage: test
script: exit 0
deploy:
stage: deploy
script: exit 0
needs: [build_1, test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build_1: pending
build_2: pending
test: created
deploy: created
transitions:
- event: success
jobs: [build_1]
expect:
pipeline: running
stages:
build: running
test: created
deploy: created
jobs:
build_1: success
build_2: pending
test: created
deploy: created
- event: drop
jobs: [build_2]
expect:
pipeline: running
stages:
build: failed
test: skipped
deploy: pending
jobs:
build_1: success
build_2: failed
test: skipped
deploy: pending
# TODO: should we run deploy?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build_1:
stage: build
script: exit 0
build_2:
stage: build
script: exit 1
test:
stage: test
script: exit 0
deploy:
stage: deploy
script: exit 0
when: always
needs: [build_1, test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build_1: pending
build_2: pending
test: created
deploy: created
transitions:
- event: success
jobs: [build_1]
expect:
pipeline: running
stages:
build: running
test: created
deploy: created
jobs:
build_1: success
build_2: pending
test: created
deploy: created
- event: drop
jobs: [build_2]
expect:
pipeline: running
stages:
build: failed
test: skipped
deploy: pending
jobs:
build_1: success
build_2: failed
test: skipped
deploy: pending
# TODO: what's the actual expected behavior here?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build:
stage: build
script: exit 1
test:
stage: test
allow_failure: true
script: exit 1
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: failed
stages:
build: failed
test: skipped
deploy: skipped
jobs:
build: failed
test: skipped
deploy: skipped
config:
build:
stage: build
script: exit 1
test:
stage: test
when: always
script: exit 0
needs: [build]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
jobs:
build: pending
test: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: running
stages:
build: failed
test: pending
jobs:
build: failed
test: pending
# TODO: Should we run `test`?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build:
stage: build
script: exit 1
test:
stage: test
when: on_failure
script: exit 0
needs: [build]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
jobs:
build: pending
test: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: running
stages:
build: failed
test: pending
jobs:
build: failed
test: pending
# TODO: Should we run `test`?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build:
stage: build
script: exit 0
test:
stage: test
when: on_failure
script: exit 0
needs: [build]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
jobs:
build: pending
test: created
transitions:
- event: success
jobs: [build]
expect:
pipeline: success
stages:
build: success
test: skipped
jobs:
build: success
test: skipped
# TODO: Should we run `test`?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build_1:
stage: build
script: exit 0
build_2:
stage: build
script: exit 0
test:
stage: test
script: exit 0
when: on_failure
deploy:
stage: deploy
script: exit 0
needs: [build_1, test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build_1: pending
build_2: pending
test: created
deploy: created
transitions:
- event: success
jobs: [build_1, build_2]
expect:
pipeline: running
stages:
build: success
test: skipped
deploy: pending
jobs:
build_1: success
build_2: success
test: skipped
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
build: success
test: skipped
deploy: success
jobs:
build_1: success
build_2: success
test: skipped
deploy: success
# TODO: should we run deploy?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build_1:
stage: build
script: exit 0
build_2:
stage: build
script: exit 0
test:
stage: test
script: exit 0
when: on_failure
deploy:
stage: deploy
script: exit 0
when: always
needs: [build_1, test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build_1: pending
build_2: pending
test: created
deploy: created
transitions:
- event: success
jobs: [build_1, build_2]
expect:
pipeline: running
stages:
build: success
test: skipped
deploy: pending
jobs:
build_1: success
build_2: success
test: skipped
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
build: success
test: skipped
deploy: success
jobs:
build_1: success
build_2: success
test: skipped
deploy: success
# TODO: should we run deploy?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
test:
stage: test
allow_failure: true
script: exit 1
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: pending
stages:
test: pending
deploy: created
jobs:
test: pending
deploy: created
transitions:
- event: drop
jobs: [test]
expect:
pipeline: pending
stages:
test: success
deploy: pending
jobs:
test: failed
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
test: success
deploy: success
jobs:
test: failed
deploy: success
config:
test:
stage: test
when: manual
allow_failure: false
script: exit 0
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: manual
stages:
test: manual
deploy: created
jobs:
test: manual
deploy: created
transitions:
- event: enqueue
jobs: [test]
expect:
pipeline: manual
stages:
test: manual
deploy: created
jobs:
test: pending
deploy: created
- event: run
jobs: [test]
expect:
pipeline: running
stages:
test: running
deploy: created
jobs:
test: running
deploy: created
- event: success
jobs: [test]
expect:
pipeline: running
stages:
test: success
deploy: pending
jobs:
test: success
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
test: success
deploy: success
jobs:
test: success
deploy: success
config:
test:
stage: test
when: manual
allow_failure: true
script: exit 1
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: created
stages:
test: skipped
deploy: created
jobs:
test: manual
deploy: created
transitions:
- event: enqueue
jobs: [test]
expect:
pipeline: pending
stages:
test: running
deploy: created
jobs:
test: pending
deploy: created
- event: run
jobs: [test]
expect:
pipeline: running
stages:
test: running
deploy: created
jobs:
test: running
deploy: created
- event: drop
jobs: [test]
expect:
pipeline: running
stages:
test: success
deploy: pending
jobs:
test: failed
deploy: pending
# TOOD: should we run deploy?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
test:
stage: test
when: manual
allow_failure: true
script: exit 1
deploy:
stage: deploy
when: always
script: exit 0
needs: [test]
init:
expect:
pipeline: created
stages:
test: skipped
deploy: created
jobs:
test: manual
deploy: created
transitions: []
# TODO: should we run `deploy`?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
test:
stage: test
when: manual
allow_failure: true
script: exit 1
deploy:
stage: deploy
when: on_failure
script: exit 0
needs: [test]
init:
expect:
pipeline: created
stages:
test: skipped
deploy: created
jobs:
test: manual
deploy: created
transitions:
- event: enqueue
jobs: [test]
expect:
pipeline: pending
stages:
test: running
deploy: created
jobs:
test: pending
deploy: created
- event: drop
jobs: [test]
expect:
pipeline: success
stages:
test: success
deploy: skipped
jobs:
test: failed
deploy: skipped
# TODO: should we run `deploy`?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
test1:
stage: test
script: exit 0
test2:
stage: test
when: manual
allow_failure: true
script: exit 1
deploy:
stage: deploy
script: exit 0
needs: [test1, test2]
init:
expect:
pipeline: pending
stages:
test: pending
deploy: created
jobs:
test1: pending
test2: manual
deploy: created
transitions:
- event: success
jobs: [test1]
expect:
pipeline: running
stages:
test: success
deploy: created
jobs:
test1: success
test2: manual
deploy: created
# TODO: should deploy run?
# Further discussions: https://gitlab.com/gitlab-org/gitlab/-/issues/213080
config:
build:
stage: build
script: exit 1
test:
stage: test
when: on_failure
script: exit 0
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: running
stages:
build: failed
test: pending
deploy: created
jobs:
build: failed
test: pending
deploy: created
- event: success
jobs: [test]
expect:
pipeline: running
stages:
build: failed
test: success
deploy: pending
jobs:
build: failed
test: success
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: failed
stages:
build: failed
test: success
deploy: success
jobs:
build: failed
test: success
deploy: success
config:
build:
stage: build
script: exit 0
test:
stage: test
when: on_failure
script: exit 0
deploy:
stage: deploy
script: exit 0
needs: [test]
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: success
jobs: [build]
expect:
pipeline: success
stages:
build: success
test: skipped
deploy: skipped
jobs:
build: success
test: skipped
deploy: skipped
config:
build:
stage: build
allow_failure: true
script: exit 1
test:
stage: test
when: on_failure
script: exit 0
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: pending
stages:
build: success
test: skipped
deploy: pending
jobs:
build: failed
test: skipped
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
build: success
test: skipped
deploy: success
jobs:
build: failed
test: skipped
deploy: success
config:
build:
stage: build
script: exit 1
test:
stage: test
script: exit 0
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: failed
stages:
build: failed
test: skipped
deploy: skipped
jobs:
build: failed
test: skipped
deploy: skipped
config:
build:
stage: build
script: exit 1
test:
stage: test
allow_failure: true
script: exit 1
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: failed
stages:
build: failed
test: skipped
deploy: skipped
jobs:
build: failed
test: skipped
deploy: skipped
config:
test:
stage: test
when: manual
allow_failure: false
script: exit 0
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: manual
stages:
test: manual
deploy: created
jobs:
test: manual
deploy: created
transitions:
- event: enqueue
jobs: [test]
expect:
pipeline: manual
stages:
test: manual
deploy: created
jobs:
test: pending
deploy: created
- event: run
jobs: [test]
expect:
pipeline: running
stages:
test: running
deploy: created
jobs:
test: running
deploy: created
- event: success
jobs: [test]
expect:
pipeline: running
stages:
test: success
deploy: pending
jobs:
test: success
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
test: success
deploy: success
jobs:
test: success
deploy: success
config:
test:
stage: test
when: manual
allow_failure: true
script: exit 1
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: pending
stages:
test: skipped
deploy: pending
jobs:
test: manual
deploy: pending
transitions:
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
test: skipped
deploy: success
jobs:
test: manual
deploy: success
- event: enqueue
jobs: [test]
expect:
pipeline: running
stages:
test: running
deploy: success
jobs:
test: pending
deploy: success
- event: drop
jobs: [test]
expect:
pipeline: success
stages:
test: success
deploy: success
jobs:
test: failed
deploy: success
config:
test:
stage: test
when: manual
allow_failure: true
script: exit 1
deploy:
stage: deploy
when: on_failure
script: exit 0
init:
expect:
pipeline: skipped
stages:
test: skipped
deploy: skipped
jobs:
test: manual
deploy: skipped
transitions:
- event: enqueue
jobs: [test]
expect:
pipeline: pending
stages:
test: running
deploy: skipped
jobs:
test: pending
deploy: skipped
- event: drop
jobs: [test]
expect:
pipeline: success
stages:
test: success
deploy: skipped
jobs:
test: failed
deploy: skipped
config:
build:
stage: build
script: exit 1
test:
stage: test
when: on_failure
script: exit 0
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: drop
jobs: [build]
expect:
pipeline: running
stages:
build: failed
test: pending
deploy: created
jobs:
build: failed
test: pending
deploy: created
- event: success
jobs: [test]
expect:
pipeline: failed
stages:
build: failed
test: success
deploy: skipped
jobs:
build: failed
test: success
deploy: skipped
config:
build:
stage: build
script: exit 0
test:
stage: test
when: on_failure
script: exit 0
deploy:
stage: deploy
script: exit 0
init:
expect:
pipeline: pending
stages:
build: pending
test: created
deploy: created
jobs:
build: pending
test: created
deploy: created
transitions:
- event: success
jobs: [build]
expect:
pipeline: running
stages:
build: success
test: skipped
deploy: pending
jobs:
build: success
test: skipped
deploy: pending
- event: success
jobs: [deploy]
expect:
pipeline: success
stages:
build: success
test: skipped
deploy: success
jobs:
build: success
test: skipped
deploy: success
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