Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/models/runtime/droplet_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ def docker_ports
end

def docker_user
return '' unless docker?

container_user = ''
if execution_metadata.present?
begin
Expand Down
7 changes: 7 additions & 0 deletions app/presenters/v3/process_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ module V3
class ProcessPresenter < BasePresenter
include VCAP::CloudController::Presenters::Mixins::MetadataPresentationHelpers

class << self
# :labels and :annotations come from MetadataPresentationHelpers
def associated_resources
super + [{ app: %i[buildpack_lifecycle_data cnb_lifecycle_data] }]
end
end

def to_hash
health_check_data = { timeout: process.health_check_timeout, invocation_timeout: process.health_check_invocation_timeout, interval: process.health_check_interval }
health_check_data[:endpoint] = process.health_check_http_endpoint if process.health_check_type == HealthCheckTypes::HTTP
Expand Down
17 changes: 17 additions & 0 deletions spec/request/processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@
allow(instances_reporters).to receive(:instances_for_processes).and_return(instances_for_processes)
end

context 'eager loading' do
let(:cnb_app) { VCAP::CloudController::AppModel.make(:cnb, space:) }
let!(:cnb_process_1) { VCAP::CloudController::ProcessModel.make(:cnb, app: cnb_app) }
let!(:cnb_process_2) { VCAP::CloudController::ProcessModel.make(:cnb, app: cnb_app) }
let(:get_processes) { -> { get '/v3/processes', nil, developer_headers } }

it 'eager loads associated data needed to present processes' do
expect { get_processes.call }.to have_queried_db_times(/SELECT .* FROM .processes. /i, 1)
expect(last_response.status).to eq(200)
expect(parsed_response['resources'].count).to eq(4)

expect { get_processes.call }.to have_queried_db_times(/SELECT .* FROM .apps. /i, 1) # instead of 4 w/o eager loading
expect { get_processes.call }.to have_queried_db_times(/SELECT .* FROM .buildpack_lifecycle_data. /i, 1) # instead of 4 w/o eager loading
expect { get_processes.call }.to have_queried_db_times(/SELECT .* FROM .cnb_lifecycle_data. /i, 1) # instead of 2 w/o eager loading
end
end

it_behaves_like 'list query endpoint' do
let(:message) { VCAP::CloudController::ProcessesListMessage }
let(:request) { '/v3/processes' }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/controllers/v3/processes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it 'eager loads associated resources that the presenter specifies' do
expect(VCAP::CloudController::ProcessListFetcher).to receive(:fetch_for_app).with(
an_instance_of(VCAP::CloudController::ProcessesListMessage),
hash_including(eager_loaded_associations: %i[labels annotations])
hash_including(eager_loaded_associations: [:labels, :annotations, { app: %i[buildpack_lifecycle_data cnb_lifecycle_data] }])
).and_call_original

get :index, params: { app_guid: app.guid }
Expand Down Expand Up @@ -103,7 +103,7 @@
it 'eager loads associated resources that the presenter specifies' do
expect(VCAP::CloudController::ProcessListFetcher).to receive(:fetch_all).with(
an_instance_of(VCAP::CloudController::ProcessesListMessage),
hash_including(eager_loaded_associations: %i[labels annotations])
hash_including(eager_loaded_associations: [:labels, :annotations, { app: %i[buildpack_lifecycle_data cnb_lifecycle_data] }])
).and_call_original

get :index
Expand Down
6 changes: 0 additions & 6 deletions spec/unit/models/runtime/droplet_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,6 @@ module VCAP::CloudController
describe '#docker_user' do
let(:droplet_model) { DropletModel.make }

context 'when the droplet DOES NOT belong to a Docker lifecycle app' do
it 'returns an empty string' do
expect(droplet_model.docker_user).to eq('')
end
end

context 'when the droplet belongs to a Docker lifecycle app' do
let(:droplet_execution_metadata) { '{"entrypoint":["/image-entrypoint.sh"],"user":"cnb"}' }
let(:droplet_model) { DropletModel.make(:docker, execution_metadata: droplet_execution_metadata) }
Expand Down