Skip to content

Commit

Permalink
delete unnecessary log, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kathap committed Jun 18, 2024
1 parent 0f8ee89 commit dbf0b61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def stats_for_app(process)

actual_lrp_info(process, stats, quota_stats, log_cache_errors, isolation_segment)
rescue CloudController::Errors::NoRunningInstances
# case when no desired_lrp exists but an actual_lrp
handle_no_running_instances(process)
rescue StandardError => e
logger.error('stats_for_app.error', error: e.to_s)
Expand Down Expand Up @@ -82,10 +81,11 @@ def build_info(state, actual_lrp, process, stats, quota_stats, log_cache_errors)
end

def handle_no_running_instances(process)
# case when no actual_lrp exists
if bbs_instances_client.lrp_instances(process).empty?
logger.info('stats_for_app.error', error: e.to_s)
[fill_unreported_instances_with_down_instances({}, process, flat: false), []]
else
# case when no desired_lrp exists but an actual_lrp
logger.debug('Actual LRP found, setting state to STOPPING', process_guid: process.guid)
actual_lrp_info(process, nil, nil, nil, nil, VCAP::CloudController::Diego::LRP_STOPPING)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
end
end

context 'when a NoRunningInstances error is thrown for desired_lrp and it does not exist an actual_lrp' do
let(:error) { CloudController::Errors::NoRunningInstances.new('No running instances ruh roh') }
let(:expected_stats_response) do
{
0 => {
state: 'DOWN',
stats: {
uptime: 0
}
}
}
end

before do
allow(bbs_instances_client).to receive(:lrp_instances).with(process).and_raise(error)
allow(bbs_instances_client).to receive(:desired_lrp_instance).with(process).and_raise(error)
end

it 'shows all instances as "DOWN" state' do
expect(instances_reporter.stats_for_app(process)).to eq([expected_stats_response, []])
end
end

context 'when process is not routable' do
let(:is_routable) { false }

Expand Down Expand Up @@ -333,7 +356,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
end
end

context 'when a NoRunningInstances error is thrown' do
context 'when a NoRunningInstances error is thrown for actual_lrp and it exists a desired_lrp' do
let(:error) { CloudController::Errors::NoRunningInstances.new('No running instances ruh roh') }
let(:expected_stats_response) do
{
Expand All @@ -345,9 +368,16 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
}
}
end
let(:bbs_desired_lrp_response) do
::Diego::Bbs::Models::DesiredLRP.new(
PlacementTags: placement_tags,
metric_tags: metrics_tags
)
end

before do
allow(bbs_instances_client).to receive(:lrp_instances).with(process).and_raise(error)
allow(bbs_instances_client).to receive_messages(desired_lrp_instance: bbs_desired_lrp_response)
end

it 'shows all instances as "DOWN"' do
Expand Down

0 comments on commit dbf0b61

Please sign in to comment.