Skip to content

Commit d299b3a

Browse files
committed
Spec for PeriodicUpdater.stop_updates
1 parent 2b9938b commit d299b3a

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

lib/cloud_controller/metrics/periodic_updater.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ def initialize(start_time, log_counter, logger, statsd_updater, prometheus_updat
1717
def setup_updates
1818
update!
1919
@update_tasks = []
20-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 600) { catch_error { update_user_count } }.execute
21-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_job_queue_length } }.execute
22-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_job_queue_load } }.execute
23-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_failed_job_count } }.execute
24-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_vitals } }.execute
25-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_log_counts } }.execute
26-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_task_stats } }.execute
27-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_deploying_count } }.execute
28-
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_webserver_stats } }.execute
20+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 600) { catch_error { update_user_count } }
21+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_job_queue_length } }
22+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_job_queue_load } }
23+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_failed_job_count } }
24+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_vitals } }
25+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_log_counts } }
26+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_task_stats } }
27+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_deploying_count } }
28+
@update_tasks << Concurrent::TimerTask.new(execution_interval: 30) { catch_error { update_webserver_stats } }
29+
@update_tasks.each(&:execute)
2930
end
3031

3132
def stop_updates

spec/unit/lib/cloud_controller/metrics/periodic_updater_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,28 @@ module VCAP::CloudController::Metrics
183183
@periodic_timers[6][:block].call
184184
end
185185
end
186+
187+
context 'when PeriodicUpdater is shut down' do
188+
it 'does nothing when updates have not been setup' do
189+
expect { periodic_updater.stop_updates }.not_to raise_error
190+
end
191+
192+
it 'shuts down all timer tasks after setup_updates' do
193+
timer_doubles = []
194+
allow(Concurrent::TimerTask).to receive(:new) do |*|
195+
dbl = double('TimerTask', execute: nil, shutdown: nil)
196+
timer_doubles << dbl
197+
dbl
198+
end
199+
200+
periodic_updater.setup_updates
201+
202+
expect(timer_doubles.size).to eq(9)
203+
expect(timer_doubles).to all(receive(:shutdown).once)
204+
205+
periodic_updater.stop_updates
206+
end
207+
end
186208
end
187209

188210
describe '#update_deploying_count' do

0 commit comments

Comments
 (0)