Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit ad1855e

Browse files
V3 Fix 🐞: Scaling a process with extreme memory results in an UnknownError
[#171659728] Authored-by: Merric De Launey <mdelauney@pivotal.io>
1 parent 05cbf3e commit ad1855e

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

app/messages/process_scale_message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ProcessScaleMessage < BaseMessage
77
validates_with NoAdditionalKeysValidator
88

99
validates :instances, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, allow_nil: true
10-
validates :memory_in_mb, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
10+
validates :memory_in_mb, numericality: { only_integer: true, greater_than: 0, less_than_or_equal_to: MAX_DB_INT }, allow_nil: true
1111
validates :disk_in_mb, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
1212
end
1313
end

spec/request/processes_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,32 @@
741741
})
742742
end
743743

744+
it 'returns a helpful error when the meemory is too large' do
745+
process = VCAP::CloudController::ProcessModel.make(
746+
:process,
747+
app: app_model,
748+
type: 'web',
749+
instances: 2,
750+
memory: 1024,
751+
disk_quota: 1024,
752+
command: 'rackup',
753+
)
754+
755+
scale_request = {
756+
memory_in_mb: 100000000000,
757+
}
758+
759+
post "/v3/processes/#{process.guid}/actions/scale", scale_request.to_json, developer_headers
760+
761+
# parsed_response = MultiJson.load(last_response.body)
762+
763+
expect(last_response.status).to eq(422)
764+
expect(parsed_response['errors'][0]['detail']).to eq 'Memory in mb must be less than or equal to 2147483647'
765+
766+
process.reload
767+
expect(process.memory).to eq(1024)
768+
end
769+
744770
it 'ensures that the memory allocation is greater than existing sidecar memory allocation' do
745771
process = VCAP::CloudController::ProcessModel.make(
746772
:process,

spec/unit/messages/process_scale_message_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ module VCAP::CloudController
7474
end
7575
end
7676

77+
context 'when memory_in_mb is > the max value allowed in the database' do
78+
let(:params) { { memory_in_mb: 0 } }
79+
80+
it 'is not valid' do
81+
message = ProcessScaleMessage.new(params)
82+
83+
expect(message).not_to be_valid
84+
expect(message.errors.count).to eq(1)
85+
expect(message.errors[:memory_in_mb]).to include('must be greater than 0')
86+
end
87+
end
88+
7789
context 'when memory_in_mb is not an integer' do
7890
let(:params) { { memory_in_mb: 3.5 } }
7991

0 commit comments

Comments
 (0)