From c81ef3041e50411166620a99e6ac80f9dc97d86e Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Mon, 20 Feb 2017 01:17:24 +0300 Subject: add auto-cancel for pending pipelines on branch, if they are not HEAD fix changelog MR reference add non-HEAD builds finder and add `created` pipelines to scope add spec for auto-cancel non-HEAD pipelines and refactor create_pipeline_service_spec more refactoring for spec adds option for auto-cancel into CI/CD settings fix spec to new configuration fix rubocop fix schema.rb fix schema.rb replace Gitlab 9.0 with 9.1 in doc change wording on pipeline settings added auto_canceled_by field as identifier of autocancel subject remove unnecessary index replace service with retry_lock replace auto_cancel_pending_pipelines boolean setting with integer (and enum in model) fix schema.rb fix schema.rb remove projekt attribute and clean up spec clean up spec withcouple of shared examples added spec for "It does not cancel current pipeline" scenario add some specs to auto-cancel add spec for another branch pipelines --- spec/services/ci/create_pipeline_service_spec.rb | 214 ++++++++++++----------- 1 file changed, 116 insertions(+), 98 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index d2f0337c260..be677facfe2 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -9,72 +9,127 @@ describe Ci::CreatePipelineService, services: true do end describe '#execute' do - def execute(params) + def execute_service(after: project.commit.id, message: 'Message', ref: 'refs/heads/master') + params = { ref: ref, + before: '00000000', + after: after, + commits: [{ message: message }] } + described_class.new(project, user, params).execute end - context 'valid params' do - let(:pipeline) do - execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: [{ message: "Message" }]) - end - + shared_examples 'a pending pipeline' do it { expect(pipeline).to be_kind_of(Ci::Pipeline) } it { expect(pipeline).to be_valid } - it { expect(pipeline).to be_persisted } it { expect(pipeline).to eq(project.pipelines.last) } it { expect(pipeline).to have_attributes(user: user) } + it { expect(pipeline).to have_attributes(status: 'pending') } it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) } end + context 'valid params' do + let(:pipeline) { execute_service } + + it_behaves_like 'a pending pipeline' + + context 'auto-cancel enabled' do + let(:pipeline_on_previous_commit) do + execute_service( + after: previous_commit_sha_from_ref('master') + ) + end + + def previous_commit_sha_from_ref(ref) + project.repository.find_commits(ref: ref, max_count: 2)[1].id + end + + before do + project.update(auto_cancel_pending_pipelines: 'enabled') + end + + it_behaves_like 'a pending pipeline' + + it 'auto cancel pending non-HEAD pipelines' do + pending_pipeline = pipeline_on_previous_commit + pipeline + + expect(pending_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by: pipeline.id) + end + + it 'does not cancel running outdated pipelines' do + running_pipeline = pipeline_on_previous_commit + running_pipeline.run + execute_service + + expect(running_pipeline.reload).to have_attributes(status: 'running', auto_canceled_by: nil) + end + + it 'cancel created outdated pipelines' do + created_pipeline = pipeline_on_previous_commit + created_pipeline.update(status: 'created') + pipeline + + expect(created_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by: pipeline.id) + end + + it 'does not cancel pipelines from the other branches' do + pending_pipeline = execute_service( + ref: 'refs/heads/feature', + after: previous_commit_sha_from_ref('feature') + ) + pipeline + + expect(pending_pipeline.reload).to have_attributes(status: 'pending', auto_canceled_by: nil) + end + end + end + context "skip tag if there is no build for it" do it "creates commit if there is appropriate job" do - result = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: [{ message: "Message" }]) - expect(result).to be_persisted + expect(execute_service).to be_persisted end it "creates commit if there is no appropriate job but deploy job has right ref setting" do config = YAML.dump({ deploy: { script: "ls", only: ["master"] } }) stub_ci_pipeline_yaml_file(config) - result = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: [{ message: "Message" }]) - expect(result).to be_persisted + expect(execute_service).to be_persisted end end it 'skips creating pipeline for refs without .gitlab-ci.yml' do stub_ci_pipeline_yaml_file(nil) - result = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: [{ message: 'Message' }]) - expect(result).not_to be_persisted + expect(execute_service).not_to be_persisted expect(Ci::Pipeline.count).to eq(0) end - it 'fails commits if yaml is invalid' do - message = 'message' - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { message } - stub_ci_pipeline_yaml_file('invalid: file: file') - commits = [{ message: message }] - pipeline = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: commits) - - expect(pipeline).to be_persisted - expect(pipeline.builds.any?).to be false - expect(pipeline.status).to eq('failed') - expect(pipeline.yaml_errors).not_to be_nil + shared_examples 'a failed pipeline' do + it 'creates failed pipeline' do + stub_ci_pipeline_yaml_file(ci_yaml) + + pipeline = execute_service(message: message) + + expect(pipeline).to be_persisted + expect(pipeline.builds.any?).to be false + expect(pipeline.status).to eq('failed') + expect(pipeline.yaml_errors).not_to be_nil + end + end + + context 'when yaml is invalid' do + let(:ci_yaml) { 'invalid: file: fiile' } + let(:message) { 'Message' } + + it_behaves_like 'a failed pipeline' + + context 'when receive git commit' do + before do + allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { message } + end + + it_behaves_like 'a failed pipeline' + end end context 'when commit contains a [ci skip] directive' do @@ -97,11 +152,7 @@ describe Ci::CreatePipelineService, services: true do ci_messages.each do |ci_message| it "skips builds creation if the commit message is #{ci_message}" do - commits = [{ message: ci_message }] - pipeline = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: commits) + pipeline = execute_service(message: ci_message) expect(pipeline).to be_persisted expect(pipeline.builds.any?).to be false @@ -109,58 +160,34 @@ describe Ci::CreatePipelineService, services: true do end end - it "does not skips builds creation if there is no [ci skip] or [skip ci] tag in commit message" do - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { "some message" } + shared_examples 'creating a pipeline' do + it 'does not skips pipeline creation' do + allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { commit_message } - commits = [{ message: "some message" }] - pipeline = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: commits) + pipeline = execute_service(message: commit_message) - expect(pipeline).to be_persisted - expect(pipeline.builds.first.name).to eq("rspec") + expect(pipeline).to be_persisted + expect(pipeline.builds.first.name).to eq("rspec") + end end - it "does not skip builds creation if the commit message is nil" do - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { nil } - - commits = [{ message: nil }] - pipeline = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: commits) + context 'when commit message does not contain [ci skip] nor [skip ci]' do + let(:commit_message) { 'some message' } - expect(pipeline).to be_persisted - expect(pipeline.builds.first.name).to eq("rspec") + it_behaves_like 'creating a pipeline' end - it "fails builds creation if there is [ci skip] tag in commit message and yaml is invalid" do - stub_ci_pipeline_yaml_file('invalid: file: fiile') - commits = [{ message: message }] - pipeline = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: commits) + context 'when commit message is nil' do + let(:commit_message) { nil } - expect(pipeline).to be_persisted - expect(pipeline.builds.any?).to be false - expect(pipeline.status).to eq("failed") - expect(pipeline.yaml_errors).not_to be_nil + it_behaves_like 'creating a pipeline' end - end - it "creates commit with failed status if yaml is invalid" do - stub_ci_pipeline_yaml_file('invalid: file') - commits = [{ message: "some message" }] - pipeline = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: commits) - - expect(pipeline).to be_persisted - expect(pipeline.status).to eq("failed") - expect(pipeline.builds.any?).to be false + context 'when there is [ci skip] tag in commit message and yaml is invalid' do + let(:ci_yaml) { 'invalid: file: fiile' } + + it_behaves_like 'a failed pipeline' + end end context 'when there are no jobs for this pipeline' do @@ -170,10 +197,7 @@ describe Ci::CreatePipelineService, services: true do end it 'does not create a new pipeline' do - result = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: [{ message: 'some msg' }]) + result = execute_service expect(result).not_to be_persisted expect(Ci::Build.all).to be_empty @@ -188,10 +212,7 @@ describe Ci::CreatePipelineService, services: true do end it 'does not create a new pipeline' do - result = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: [{ message: 'some msg' }]) + result = execute_service expect(result).to be_persisted expect(result.manual_actions).not_to be_empty @@ -205,10 +226,7 @@ describe Ci::CreatePipelineService, services: true do end it 'creates the environment' do - result = execute(ref: 'refs/heads/master', - before: '00000000', - after: project.commit.id, - commits: [{ message: 'some msg' }]) + result = execute_service expect(result).to be_persisted expect(Environment.find_by(name: "review/master")).not_to be_nil -- cgit v1.2.3 From c77b1cb0fb8a156faa3f7fa828b6838b7b89d439 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 12:50:56 +0300 Subject: add `does not cancel HEAD pipeline` spec --- spec/services/ci/create_pipeline_service_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index be677facfe2..3bff0157fda 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -47,7 +47,13 @@ describe Ci::CreatePipelineService, services: true do project.update(auto_cancel_pending_pipelines: 'enabled') end - it_behaves_like 'a pending pipeline' + it 'does not cancel HEAD pipeline' do + pipeline + previous_pipeline = pipeline_on_previous_commit + + expect(pipeline.reload) + .to have_attributes(status: 'pending', auto_canceled_by: nil) + end it 'auto cancel pending non-HEAD pipelines' do pending_pipeline = pipeline_on_previous_commit -- cgit v1.2.3 From 9bdb869a0aee50ac03ff8e2a630d9a40fce1a59f Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 13:35:34 +0300 Subject: fix typo --- spec/services/ci/create_pipeline_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 3bff0157fda..cd63eeac5fa 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -167,7 +167,7 @@ describe Ci::CreatePipelineService, services: true do end shared_examples 'creating a pipeline' do - it 'does not skips pipeline creation' do + it 'does not skip pipeline creation' do allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { commit_message } pipeline = execute_service(message: commit_message) -- cgit v1.2.3 From 40f67c1da84379e293db14b61dc7390bc4d0a4c4 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 13:49:14 +0300 Subject: more brief way of get parent commit --- spec/services/ci/create_pipeline_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index cd63eeac5fa..a61c17c66f1 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -40,7 +40,7 @@ describe Ci::CreatePipelineService, services: true do end def previous_commit_sha_from_ref(ref) - project.repository.find_commits(ref: ref, max_count: 2)[1].id + project.commit(ref).parent.sha end before do -- cgit v1.2.3 From a4d08e6babbbdbd44267aebdcccd2cc2c63e48ed Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 14:46:56 +0300 Subject: rename `auto_canceled_by` and add foreign key --- spec/services/ci/create_pipeline_service_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index a61c17c66f1..4c23a371484 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -52,14 +52,14 @@ describe Ci::CreatePipelineService, services: true do previous_pipeline = pipeline_on_previous_commit expect(pipeline.reload) - .to have_attributes(status: 'pending', auto_canceled_by: nil) + .to have_attributes(status: 'pending', auto_canceled_by_id: nil) end it 'auto cancel pending non-HEAD pipelines' do pending_pipeline = pipeline_on_previous_commit pipeline - expect(pending_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by: pipeline.id) + expect(pending_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by_id: pipeline.id) end it 'does not cancel running outdated pipelines' do @@ -67,7 +67,7 @@ describe Ci::CreatePipelineService, services: true do running_pipeline.run execute_service - expect(running_pipeline.reload).to have_attributes(status: 'running', auto_canceled_by: nil) + expect(running_pipeline.reload).to have_attributes(status: 'running', auto_canceled_by_id: nil) end it 'cancel created outdated pipelines' do @@ -75,7 +75,7 @@ describe Ci::CreatePipelineService, services: true do created_pipeline.update(status: 'created') pipeline - expect(created_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by: pipeline.id) + expect(created_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by_id: pipeline.id) end it 'does not cancel pipelines from the other branches' do @@ -85,7 +85,7 @@ describe Ci::CreatePipelineService, services: true do ) pipeline - expect(pending_pipeline.reload).to have_attributes(status: 'pending', auto_canceled_by: nil) + expect(pending_pipeline.reload).to have_attributes(status: 'pending', auto_canceled_by_id: nil) end end end -- cgit v1.2.3 From b5c286995c350557fa96ab4b634c8495fa5e4888 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 17:49:01 +0300 Subject: fix rubocop --- spec/services/ci/create_pipeline_service_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 4c23a371484..b89ed7dcf44 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -39,17 +39,17 @@ describe Ci::CreatePipelineService, services: true do ) end - def previous_commit_sha_from_ref(ref) - project.commit(ref).parent.sha - end - before do project.update(auto_cancel_pending_pipelines: 'enabled') end + def previous_commit_sha_from_ref(ref) + project.commit(ref).parent.sha + end + it 'does not cancel HEAD pipeline' do pipeline - previous_pipeline = pipeline_on_previous_commit + pipeline_on_previous_commit expect(pipeline.reload) .to have_attributes(status: 'pending', auto_canceled_by_id: nil) -- cgit v1.2.3 From d2f2168b51284bee445e10d7ad399175ed51c539 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Mon, 20 Mar 2017 23:52:35 +0300 Subject: remove `a pending pipeline` shared example --- spec/services/ci/create_pipeline_service_spec.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index b89ed7dcf44..c287fe42ab2 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -18,19 +18,15 @@ describe Ci::CreatePipelineService, services: true do described_class.new(project, user, params).execute end - shared_examples 'a pending pipeline' do + context 'valid params' do + let(:pipeline) { execute_service } + it { expect(pipeline).to be_kind_of(Ci::Pipeline) } it { expect(pipeline).to be_valid } it { expect(pipeline).to eq(project.pipelines.last) } it { expect(pipeline).to have_attributes(user: user) } it { expect(pipeline).to have_attributes(status: 'pending') } it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) } - end - - context 'valid params' do - let(:pipeline) { execute_service } - - it_behaves_like 'a pending pipeline' context 'auto-cancel enabled' do let(:pipeline_on_previous_commit) do -- cgit v1.2.3 From b49e79662e8157d7feb371737f6350dce11118e3 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Tue, 21 Mar 2017 00:39:27 +0300 Subject: refactor spec --- spec/services/ci/create_pipeline_service_spec.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index c287fe42ab2..a3330367f96 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -47,31 +47,28 @@ describe Ci::CreatePipelineService, services: true do pipeline pipeline_on_previous_commit - expect(pipeline.reload) - .to have_attributes(status: 'pending', auto_canceled_by_id: nil) + expect(pipeline.reload).to have_attributes(status: 'pending', auto_canceled_by_id: nil) end it 'auto cancel pending non-HEAD pipelines' do - pending_pipeline = pipeline_on_previous_commit + pipeline_on_previous_commit pipeline - expect(pending_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by_id: pipeline.id) + expect(pipeline_on_previous_commit.reload).to have_attributes(status: 'canceled', auto_canceled_by_id: pipeline.id) end it 'does not cancel running outdated pipelines' do - running_pipeline = pipeline_on_previous_commit - running_pipeline.run + pipeline_on_previous_commit.run execute_service - expect(running_pipeline.reload).to have_attributes(status: 'running', auto_canceled_by_id: nil) + expect(pipeline_on_previous_commit.reload).to have_attributes(status: 'running', auto_canceled_by_id: nil) end it 'cancel created outdated pipelines' do - created_pipeline = pipeline_on_previous_commit - created_pipeline.update(status: 'created') + pipeline_on_previous_commit.update(status: 'created') pipeline - expect(created_pipeline.reload).to have_attributes(status: 'canceled', auto_canceled_by_id: pipeline.id) + expect(pipeline_on_previous_commit.reload).to have_attributes(status: 'canceled', auto_canceled_by_id: pipeline.id) end it 'does not cancel pipelines from the other branches' do -- cgit v1.2.3 From f7014cd5bc776f9829818e535baf9db70387a416 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Apr 2017 03:23:36 +0800 Subject: Add a test to make sure it's not auto-canceling whenever the feature is disabled in the project. --- spec/services/ci/create_pipeline_service_spec.rb | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index a3330367f96..fa5014cee07 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -21,6 +21,12 @@ describe Ci::CreatePipelineService, services: true do context 'valid params' do let(:pipeline) { execute_service } + let(:pipeline_on_previous_commit) do + execute_service( + after: previous_commit_sha_from_ref('master') + ) + end + it { expect(pipeline).to be_kind_of(Ci::Pipeline) } it { expect(pipeline).to be_valid } it { expect(pipeline).to eq(project.pipelines.last) } @@ -29,20 +35,10 @@ describe Ci::CreatePipelineService, services: true do it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) } context 'auto-cancel enabled' do - let(:pipeline_on_previous_commit) do - execute_service( - after: previous_commit_sha_from_ref('master') - ) - end - before do project.update(auto_cancel_pending_pipelines: 'enabled') end - def previous_commit_sha_from_ref(ref) - project.commit(ref).parent.sha - end - it 'does not cancel HEAD pipeline' do pipeline pipeline_on_previous_commit @@ -81,6 +77,24 @@ describe Ci::CreatePipelineService, services: true do expect(pending_pipeline.reload).to have_attributes(status: 'pending', auto_canceled_by_id: nil) end end + + context 'auto-cancel disabled' do + before do + project.update(auto_cancel_pending_pipelines: 'disabled') + end + + it 'does not auto cancel pending non-HEAD pipelines' do + pipeline_on_previous_commit + pipeline + + expect(pipeline_on_previous_commit.reload) + .to have_attributes(status: 'pending', auto_canceled_by_id: nil) + end + end + + def previous_commit_sha_from_ref(ref) + project.commit(ref).parent.sha + end end context "skip tag if there is no build for it" do -- cgit v1.2.3 From 4f435c6c3a641d7c3dd826c316d5372fdbfd2161 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 7 Apr 2017 01:29:11 +0800 Subject: Reload pipeline to make sure it's updated --- spec/services/ci/process_pipeline_service_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/process_pipeline_service_spec.rb b/spec/services/ci/process_pipeline_service_spec.rb index bb98fb37a90..d7df6c5c22e 100644 --- a/spec/services/ci/process_pipeline_service_spec.rb +++ b/spec/services/ci/process_pipeline_service_spec.rb @@ -462,7 +462,10 @@ describe Ci::ProcessPipelineService, '#execute', :services do builds.find_by(name: name).play(user) end - delegate :manual_actions, to: :pipeline + def manual_actions + pipeline.reload + pipeline.manual_actions + end def create_build(name, **opts) create(:ci_build, :created, pipeline: pipeline, name: name, **opts) -- cgit v1.2.3 From beedfc8d94c96342a82e27b8c7b836ca7002cb43 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 7 Apr 2017 01:36:26 +0800 Subject: Fix test by ignoring auto_canceled_by for jobs --- spec/services/ci/retry_build_service_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index 8567817147b..b2d37657770 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -16,20 +16,21 @@ describe Ci::RetryBuildService, :services do %i[id status user token coverage trace runner artifacts_expire_at artifacts_file artifacts_metadata artifacts_size created_at updated_at started_at finished_at queued_at erased_by - erased_at].freeze + erased_at auto_canceled_by].freeze IGNORE_ACCESSORS = %i[type lock_version target_url base_tags commit_id deployments erased_by_id last_deployment project_id runner_id tag_taggings taggings tags trigger_request_id - user_id].freeze + user_id auto_canceled_by_id].freeze shared_examples 'build duplication' do let(:build) do create(:ci_build, :failed, :artifacts_expired, :erased, :queued, :coverage, :tags, :allowed_to_fail, :on_tag, :teardown_environment, :triggered, :trace, - description: 'some build', pipeline: pipeline) + description: 'some build', pipeline: pipeline, + auto_canceled_by: create(:ci_empty_pipeline)) end describe 'clone accessors' do -- cgit v1.2.3 From 57c353fca7121a120142161b253004f33d815766 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 6 Apr 2017 21:57:04 +0200 Subject: Fix tests and review --- spec/services/ci/process_pipeline_service_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/process_pipeline_service_spec.rb b/spec/services/ci/process_pipeline_service_spec.rb index d7df6c5c22e..245e19822f3 100644 --- a/spec/services/ci/process_pipeline_service_spec.rb +++ b/spec/services/ci/process_pipeline_service_spec.rb @@ -463,8 +463,7 @@ describe Ci::ProcessPipelineService, '#execute', :services do end def manual_actions - pipeline.reload - pipeline.manual_actions + pipeline.manual_actions(true) end def create_build(name, **opts) -- cgit v1.2.3 From 847b9c82326d4fa1c4ab28f0f500a374e92728cb Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Tue, 4 Apr 2017 17:38:16 +0200 Subject: Use Etag caching for pipelines json Enable caching in the Etag::Middleware and when a pipeline changes status, expire the cache for the project pipelines path. --- spec/services/ci/expire_pipeline_cache_service_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 spec/services/ci/expire_pipeline_cache_service_spec.rb (limited to 'spec/services/ci') diff --git a/spec/services/ci/expire_pipeline_cache_service_spec.rb b/spec/services/ci/expire_pipeline_cache_service_spec.rb new file mode 100644 index 00000000000..b8250f99c5a --- /dev/null +++ b/spec/services/ci/expire_pipeline_cache_service_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Ci::ExpirePipelineCacheService, services: true do + let(:user) { create(:user) } + let(:project) { create(:empty_project) } + let(:pipeline) { create(:ci_pipeline, project: project) } + subject { described_class.new(project, user) } + + describe '#execute' do + it 'invalidate Etag caching for project pipelines path' do + path = "/#{project.full_path}/pipelines.json" + + expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(path) + + subject.execute(pipeline) + end + end +end -- cgit v1.2.3 From 9e89c93e167d66644fd771b106be5ce01b899fcf Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Wed, 5 Apr 2017 16:36:14 +0200 Subject: Enable polling for pipelines table other pages Also poll for pipeline changes on: - Pipeline table on commit page - Pipeline table on merge request page - Pipeline table on new merge request page --- spec/services/ci/expire_pipeline_cache_service_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/services/ci') diff --git a/spec/services/ci/expire_pipeline_cache_service_spec.rb b/spec/services/ci/expire_pipeline_cache_service_spec.rb index b8250f99c5a..3c735872c30 100644 --- a/spec/services/ci/expire_pipeline_cache_service_spec.rb +++ b/spec/services/ci/expire_pipeline_cache_service_spec.rb @@ -8,9 +8,11 @@ describe Ci::ExpirePipelineCacheService, services: true do describe '#execute' do it 'invalidate Etag caching for project pipelines path' do - path = "/#{project.full_path}/pipelines.json" + pipelines_path = "/#{project.full_path}/pipelines.json" + new_mr_pipelines_path = "/#{project.full_path}/merge_requests/new.json" - expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(path) + expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(pipelines_path) + expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(new_mr_pipelines_path) subject.execute(pipeline) end -- cgit v1.2.3 From 9eded57dd2b4d23e43b485c448abb92359e6933e Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Fri, 7 Apr 2017 10:56:35 +0200 Subject: Use `Ci::ExpirePipelineCacheService` to set `ProjectPipelinestatus` --- spec/services/ci/expire_pipeline_cache_service_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/services/ci') diff --git a/spec/services/ci/expire_pipeline_cache_service_spec.rb b/spec/services/ci/expire_pipeline_cache_service_spec.rb index 3c735872c30..166c6dfc93e 100644 --- a/spec/services/ci/expire_pipeline_cache_service_spec.rb +++ b/spec/services/ci/expire_pipeline_cache_service_spec.rb @@ -16,5 +16,12 @@ describe Ci::ExpirePipelineCacheService, services: true do subject.execute(pipeline) end + + it 'updates the cached status for a project' do + expect(Gitlab::Cache::Ci::ProjectPipelineStatus).to receive(:update_for_pipeline). + with(pipeline) + + subject.execute(pipeline) + end end end -- cgit v1.2.3