Skip to content

Commit 4126f10

Browse files
committed
reorganize tests
1 parent 19ade00 commit 4126f10

File tree

12 files changed

+316
-111
lines changed

12 files changed

+316
-111
lines changed

lib/cloud_controller/deployment_updater/actions/canary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def call
1818
return unless deployment.state == DeploymentModel::PREPAUSED_STATE
1919
return unless Calculators::AllInstancesRoutable.new(deployment, logger).call
2020

21-
ScaleDownSuperseded.new(deployment).call
21+
ScaleDownCanceled.new(deployment).call
2222

2323
deployment.update(
2424
last_healthy_at: Time.now,

lib/cloud_controller/deployment_updater/actions/cancel.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
require 'cloud_controller/deployment_updater/calculators/find_interim_web_process'
2-
require 'cloud_controller/deployment_updater/actions/cleanup_web_processes'
3-
42
module VCAP::CloudController
53
module DeploymentUpdater
64
module Actions
@@ -26,7 +24,7 @@ def call
2624

2725
prior_web_process.update(instances: deployment.original_web_process_instance_count)
2826

29-
CleanupWebProcesses.new(deployment, prior_web_process).call
27+
app.web_processes.reject { |p| p.guid == prior_web_process.guid }.map(&:destroy)
3028

3129
deployment.update(
3230
state: DeploymentModel::CANCELED_STATE,

lib/cloud_controller/deployment_updater/actions/cleanup_web_processes.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/cloud_controller/deployment_updater/actions/finalize.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'cloud_controller/deployment_updater/actions/cleanup_web_processes'
21
module VCAP::CloudController
32
module DeploymentUpdater
43
module Actions
@@ -12,7 +11,7 @@ def initialize(deployment)
1211
end
1312

1413
def call
15-
CleanupWebProcesses.new(deployment, deploying_web_process).call
14+
app.web_processes.reject { |p| p.guid == deploying_web_process.guid }.map(&:destroy)
1615

1716
update_non_web_processes
1817
restart_non_web_processes

lib/cloud_controller/deployment_updater/actions/scale.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def call
3636
return
3737
end
3838

39-
ScaleDownSuperseded.new(deployment).call
39+
ScaleDownCanceled.new(deployment).call
4040
ScaleDownOldProcess.new(deployment, oldest_web_process_with_instances, instances_to_scale_down).call
4141

4242
deploying_web_process.update(instances: instances_to_scale_up)

lib/cloud_controller/deployment_updater/actions/scale_down_superseded.rb renamed to lib/cloud_controller/deployment_updater/actions/scale_down_canceled.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module VCAP::CloudController
22
module DeploymentUpdater
33
module Actions
4-
class ScaleDownSuperseded
4+
class ScaleDownCanceled
55
attr_reader :deployment
66

77
def initialize(deployment)

lib/cloud_controller/deployment_updater/actions/scale_down_old_process.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(deployment, process, instances_to_scale_down)
1212
end
1313

1414
def call
15-
if process.instances <= deployment.max_in_flight && is_interim_process?(process)
15+
if process.instances <= instances_to_scale_down && is_interim_process?(process)
1616
process.destroy
1717
return
1818
end

spec/support/fakes/blueprints.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,13 @@ module VCAP::CloudController
821821
end
822822
end
823823

824+
RevisionModel.blueprint(:no_commands) do
825+
app { AppModel.make }
826+
droplet { DropletModel.make(app:) }
827+
process_command_guids { [] }
828+
description { 'blank' }
829+
end
830+
824831
RevisionModel.blueprint(:custom_web_command) do
825832
app { AppModel.make }
826833
droplet { DropletModel.make(app:) }
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
require 'spec_helper'
2+
require 'cloud_controller/deployment_updater/actions/finalize'
3+
4+
module VCAP::CloudController
5+
RSpec.describe DeploymentUpdater::Actions::Finalize do
6+
subject(:finalize_action) { DeploymentUpdater::Actions::Finalize.new(deployment) }
7+
8+
let(:app) { AppModel.make(revisions_enabled: true) }
9+
let(:droplet) { DropletModel.make(app: app, process_types: { 'web' => 'serve', 'worker' => 'work' }) }
10+
11+
let(:state) { DeploymentModel::DEPLOYING_STATE }
12+
13+
let!(:old_web_process) do
14+
ProcessModel.make(
15+
instances: 3,
16+
created_at: 3.hours.ago,
17+
type: ProcessTypes::WEB,
18+
guid: 'guid-original',
19+
app: app
20+
)
21+
end
22+
23+
let!(:old_worker_process) do
24+
ProcessModel.make(
25+
instances: 3,
26+
type: 'worker',
27+
command: 'old_command',
28+
guid: 'worker-guid-original',
29+
app: app
30+
)
31+
end
32+
33+
let!(:old_nonweb_process) do
34+
ProcessModel.make(
35+
instances: 3,
36+
type: 'nonweb',
37+
command: nil,
38+
guid: 'nonweb-guid-original',
39+
app: app
40+
)
41+
end
42+
43+
let(:revision) { RevisionModel.make(:no_commands, app: app, droplet: droplet, version: 300) }
44+
45+
let!(:web_process_command) do
46+
RevisionProcessCommandModel.make(
47+
revision: revision,
48+
process_type: 'web',
49+
process_command: 'new_web_command'
50+
)
51+
end
52+
53+
let!(:worker_process_command) do
54+
RevisionProcessCommandModel.make(
55+
revision: revision,
56+
process_type: 'worker',
57+
process_command: 'new_worker_command'
58+
)
59+
end
60+
61+
let!(:deploying_web_process) do
62+
ProcessModel.make(
63+
app: app,
64+
type: ProcessTypes::WEB,
65+
instances: 3,
66+
guid: 'guid-final',
67+
revision: revision,
68+
state: ProcessModel::STOPPED
69+
)
70+
end
71+
72+
let!(:interim_deploying_web_process) do
73+
ProcessModel.make(
74+
app: app,
75+
created_at: 1.hour.ago,
76+
type: ProcessTypes::WEB,
77+
instances: 1,
78+
guid: 'guid-interim'
79+
)
80+
end
81+
82+
let(:deployment) do
83+
DeploymentModel.make(
84+
app: app,
85+
deploying_web_process: deploying_web_process,
86+
state: state,
87+
original_web_process_instance_count: 3,
88+
max_in_flight: 1
89+
)
90+
end
91+
92+
let(:diego_instances_reporter) { instance_double(Diego::InstancesReporter) }
93+
let(:all_instances_results) do
94+
{
95+
0 => { state: 'RUNNING', uptime: 50, since: 2, routable: true },
96+
1 => { state: 'RUNNING', uptime: 50, since: 2, routable: true },
97+
2 => { state: 'RUNNING', uptime: 50, since: 2, routable: true }
98+
}
99+
end
100+
let(:instances_reporters) { double(:instance_reporters) }
101+
102+
before do
103+
allow(CloudController::DependencyLocator.instance).to receive(:instances_reporters).and_return(instances_reporters)
104+
allow(instances_reporters).to receive(:all_instances_for_app).and_return(all_instances_results)
105+
allow(ProcessRestart).to receive(:restart)
106+
end
107+
108+
it 'updates the commands of non-web processes from the revision commands' do
109+
subject.call
110+
expect(old_worker_process.reload.command).to eq('new_worker_command')
111+
end
112+
113+
it 'puts the deployment into its finished DEPLOYED_STATE' do
114+
subject.call
115+
deployment.reload
116+
expect(deployment.state).to eq(DeploymentModel::DEPLOYED_STATE)
117+
expect(deployment.status_value).to eq(DeploymentModel::FINALIZED_STATUS_VALUE)
118+
expect(deployment.status_reason).to eq(DeploymentModel::DEPLOYED_STATUS_REASON)
119+
end
120+
121+
it 'restarts the non-web processes with the deploying process revision, but not the web process' do
122+
subject.call
123+
124+
expect(ProcessRestart).
125+
to have_received(:restart).
126+
with(process: old_worker_process, config: TestConfig.config_instance, stop_in_runtime: true, revision: revision)
127+
128+
expect(ProcessRestart).
129+
to have_received(:restart).
130+
with(process: old_nonweb_process, config: TestConfig.config_instance, stop_in_runtime: true, revision: revision)
131+
132+
expect(ProcessRestart).
133+
not_to have_received(:restart).
134+
with(process: old_web_process, config: TestConfig.config_instance, stop_in_runtime: true)
135+
136+
expect(ProcessRestart).
137+
not_to have_received(:restart).
138+
with(process: deploying_web_process, config: TestConfig.config_instance, stop_in_runtime: true)
139+
end
140+
141+
it 'cleans up any extra processes from the deployment train' do
142+
subject.call
143+
expect(ProcessModel.find(guid: interim_deploying_web_process.guid)).to be_nil
144+
end
145+
146+
context 'when revisions are disabled so the deploying web process does not have one' do
147+
before do
148+
deploying_web_process.update(revision: nil)
149+
end
150+
151+
it 'leaves the non-web process commands alone' do
152+
subject.call
153+
154+
expect(old_worker_process.reload.command).to eq('old_command')
155+
expect(old_nonweb_process.reload.command).to be_nil
156+
end
157+
end
158+
159+
it 'replaces the existing web process with the deploying_web_process' do
160+
deploying_web_process_guid = deploying_web_process.guid
161+
expect(ProcessModel.map(&:type)).to match_array(%w[web web web worker nonweb])
162+
163+
subject.call
164+
165+
deployment.reload
166+
deployment.app.reload
167+
168+
after_web_process = deployment.app.web_processes.first
169+
expect(after_web_process.guid).to eq(deploying_web_process_guid)
170+
expect(after_web_process.instances).to eq(3)
171+
172+
expect(ProcessModel.find(guid: deploying_web_process_guid)).not_to be_nil
173+
expect(ProcessModel.find(guid: deployment.app.guid)).to be_nil
174+
175+
expect(ProcessModel.map(&:type)).to match_array(%w[web worker nonweb])
176+
end
177+
end
178+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require 'spec_helper'
2+
require 'cloud_controller/deployment_updater/actions/scale_down_canceled'
3+
4+
module VCAP::CloudController
5+
RSpec.describe DeploymentUpdater::Actions::ScaleDownCanceled do
6+
subject(:finalize_action) { DeploymentUpdater::Actions::ScaleDownCanceled.new(deployment) }
7+
8+
let(:app) { AppModel.make(revisions_enabled: true) }
9+
let(:droplet) { DropletModel.make(app: app, process_types: { 'web' => 'serve', 'worker' => 'work' }) }
10+
11+
let(:state) { DeploymentModel::DEPLOYING_STATE }
12+
13+
let!(:deploying_web_process) do
14+
ProcessModel.make(
15+
app: app,
16+
type: ProcessTypes::WEB,
17+
instances: 3,
18+
guid: 'guid-final',
19+
state: ProcessModel::STOPPED
20+
)
21+
end
22+
23+
let!(:interim_canceling_web_process) do
24+
ProcessModel.make(
25+
app: app,
26+
created_at: 1.hour.ago,
27+
type: ProcessTypes::WEB,
28+
instances: 1,
29+
guid: 'guid-canceling'
30+
)
31+
end
32+
33+
let(:deployment) do
34+
DeploymentModel.make(
35+
app: app,
36+
deploying_web_process: deploying_web_process,
37+
state: state,
38+
original_web_process_instance_count: 3,
39+
max_in_flight: 1
40+
)
41+
end
42+
43+
let!(:interim_canceled_superseded_deployment) do
44+
DeploymentModel.make(
45+
deploying_web_process: interim_canceling_web_process,
46+
state: 'CANCELED',
47+
status_reason: 'SUPERSEDED'
48+
)
49+
end
50+
51+
context 'when there is an interim deployment that has been SUPERSEDED (CANCELED)' do
52+
it 'scales the canceled web process to zero' do
53+
subject.call
54+
expect(interim_canceling_web_process.reload.instances).to eq(0)
55+
end
56+
end
57+
end
58+
end

0 commit comments

Comments
 (0)