Skip to content

Commit 487580b

Browse files
authored
Don't assume a process with > 0 instances exists (#4251)
* also lock all web_processes for an app during a scaling action
1 parent 9d4dee3 commit 487580b

File tree

2 files changed

+10
-7
lines changed
  • lib/cloud_controller/deployment_updater/actions
  • spec/unit/lib/cloud_controller/deployment_updater/actions

2 files changed

+10
-7
lines changed

lib/cloud_controller/deployment_updater/actions/scale.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def call
2828

2929
app.lock!
3030

31-
oldest_web_process_with_instances.lock!
32-
deploying_web_process.lock!
31+
app.web_processes.each(&:lock!)
3332

3433
deployment.update(
3534
status_value: DeploymentModel::ACTIVE_STATUS_VALUE,
@@ -52,11 +51,6 @@ def call
5251

5352
private
5453

55-
def oldest_web_process_with_instances
56-
# TODO: lock all web processes? We might alter all of them, depending on max-in-flight size
57-
@oldest_web_process_with_instances ||= app.web_processes.select { |process| process.instances > 0 }.min_by { |p| [p.created_at, p.id] }
58-
end
59-
6054
def instance_count_summary
6155
@instance_count_summary ||= instance_reporters.instance_count_summary(deploying_web_process)
6256
end

spec/unit/lib/cloud_controller/deployment_updater/actions/scale_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ module VCAP::CloudController
8989
}.by(1)
9090
end
9191

92+
context 'when the app has been scaled to 0 instances' do
93+
let(:current_web_instances) { 0 }
94+
let(:target_total_instance_count) { 0 }
95+
96+
it 'finishes scaling' do
97+
expect(subject.call).to be true
98+
end
99+
end
100+
92101
context 'when the max_in_flight is set to 2' do
93102
let(:deployment) do
94103
DeploymentModel.make(

0 commit comments

Comments
 (0)