diff options
Diffstat (limited to 'spec/models/deployment_spec.rb')
-rw-r--r-- | spec/models/deployment_spec.rb | 148 |
1 files changed, 48 insertions, 100 deletions
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index a58d32dfe5d..0a4ee73f3d3 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -139,29 +139,16 @@ RSpec.describe Deployment do end end - it 'executes deployment hooks' do + it 'executes Deployments::HooksWorker asynchronously' do freeze_time do - expect(deployment).to receive(:execute_hooks).with(Time.current) + expect(Deployments::HooksWorker) + .to receive(:perform_async).with(deployment_id: deployment.id, status: 'running', + status_changed_at: Time.current) deployment.run! end end - context 'when `deployment_hooks_skip_worker` flag is disabled' do - before do - stub_feature_flags(deployment_hooks_skip_worker: false) - end - - it 'executes Deployments::HooksWorker asynchronously' do - freeze_time do - expect(Deployments::HooksWorker) - .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current) - - deployment.run! - end - end - end - it 'executes Deployments::DropOlderDeploymentsWorker asynchronously' do expect(Deployments::DropOlderDeploymentsWorker) .to receive(:perform_async).once.with(deployment.id) @@ -189,28 +176,15 @@ RSpec.describe Deployment do deployment.succeed! end - it 'executes deployment hooks' do + it 'executes Deployments::HooksWorker asynchronously' do freeze_time do - expect(deployment).to receive(:execute_hooks).with(Time.current) + expect(Deployments::HooksWorker) + .to receive(:perform_async).with(deployment_id: deployment.id, status: 'success', + status_changed_at: Time.current) deployment.succeed! end end - - context 'when `deployment_hooks_skip_worker` flag is disabled' do - before do - stub_feature_flags(deployment_hooks_skip_worker: false) - end - - it 'executes Deployments::HooksWorker asynchronously' do - freeze_time do - expect(Deployments::HooksWorker) - .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current) - - deployment.succeed! - end - end - end end context 'when deployment failed' do @@ -232,28 +206,15 @@ RSpec.describe Deployment do deployment.drop! end - it 'executes deployment hooks' do + it 'executes Deployments::HooksWorker asynchronously' do freeze_time do - expect(deployment).to receive(:execute_hooks).with(Time.current) + expect(Deployments::HooksWorker) + .to receive(:perform_async).with(deployment_id: deployment.id, status: 'failed', + status_changed_at: Time.current) deployment.drop! end end - - context 'when `deployment_hooks_skip_worker` flag is disabled' do - before do - stub_feature_flags(deployment_hooks_skip_worker: false) - end - - it 'executes Deployments::HooksWorker asynchronously' do - freeze_time do - expect(Deployments::HooksWorker) - .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current) - - deployment.drop! - end - end - end end context 'when deployment was canceled' do @@ -275,28 +236,15 @@ RSpec.describe Deployment do deployment.cancel! end - it 'executes deployment hooks' do + it 'executes Deployments::HooksWorker asynchronously' do freeze_time do - expect(deployment).to receive(:execute_hooks).with(Time.current) + expect(Deployments::HooksWorker) + .to receive(:perform_async).with(deployment_id: deployment.id, status: 'canceled', + status_changed_at: Time.current) deployment.cancel! end end - - context 'when `deployment_hooks_skip_worker` flag is disabled' do - before do - stub_feature_flags(deployment_hooks_skip_worker: false) - end - - it 'executes Deployments::HooksWorker asynchronously' do - freeze_time do - expect(Deployments::HooksWorker) - .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current) - - deployment.cancel! - end - end - end end context 'when deployment was skipped' do @@ -324,12 +272,6 @@ RSpec.describe Deployment do deployment.skip! end end - - it 'does not execute deployment hooks' do - expect(deployment).not_to receive(:execute_hooks) - - deployment.skip! - end end context 'when deployment is blocked' do @@ -353,12 +295,6 @@ RSpec.describe Deployment do deployment.block! end - - it 'does not execute deployment hooks' do - expect(deployment).not_to receive(:execute_hooks) - - deployment.block! - end end describe 'synching status to Jira' do @@ -756,6 +692,37 @@ RSpec.describe Deployment do .to contain_exactly(stop_env_b) end end + + context 'When last deployment for environment is a retried build' do + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:environment_b) { create(:environment, project: project) } + + let(:build_a) do + create(:ci_build, :success, project: project, pipeline: pipeline, environment: environment.name) + end + + let(:build_b) do + create(:ci_build, :success, project: project, pipeline: pipeline, environment: environment_b.name) + end + + let!(:deployment_a) do + create(:deployment, :success, project: project, environment: environment, deployable: build_a) + end + + let!(:deployment_b) do + create(:deployment, :success, project: project, environment: environment_b, deployable: build_b) + end + + before do + # Retry build_b + build_b.update!(retried: true) + + # New successful build after retry. + create(:ci_build, :success, project: project, pipeline: pipeline, environment: environment_b.name) + end + + it { expect(subject_method(environment_b)).not_to be_nil } + end end end @@ -1052,30 +1019,11 @@ RSpec.describe Deployment do expect(Deployments::UpdateEnvironmentWorker).to receive(:perform_async) expect(Deployments::LinkMergeRequestWorker).to receive(:perform_async) expect(Deployments::ArchiveInProjectWorker).to receive(:perform_async) + expect(Deployments::HooksWorker).to receive(:perform_async) expect(deploy.update_status('success')).to eq(true) end - context 'when `deployment_hooks_skip_worker` flag is disabled' do - before do - stub_feature_flags(deployment_hooks_skip_worker: false) - end - - it 'schedules `Deployments::HooksWorker` when finishing a deploy' do - expect(Deployments::HooksWorker).to receive(:perform_async) - - deploy.update_status('success') - end - end - - it 'executes deployment hooks when finishing a deploy' do - freeze_time do - expect(deploy).to receive(:execute_hooks).with(Time.current) - - deploy.update_status('success') - end - end - it 'updates finished_at when transitioning to a finished status' do freeze_time do deploy.update_status('success') |