@@ -12,21 +12,6 @@ module VCAP::CloudController::Metrics
1212 let ( :log_counter ) { double ( :log_counter , counts : { } ) }
1313 let ( :logger ) { double ( :logger ) }
1414
15- before do
16- allow ( EventMachine ) . to receive ( :connection_count ) . and_return ( 123 )
17-
18- allow ( EventMachine ) . to receive ( :instance_variable_get ) do |instance_var |
19- case instance_var
20- when :@threadqueue
21- threadqueue
22- when :@resultqueue
23- resultqueue
24- else
25- raise "Unexpected call: #{ instance_var } "
26- end
27- end
28- end
29-
3015 describe 'task stats' do
3116 before do
3217 allow ( statsd_updater ) . to receive ( :update_task_stats )
@@ -73,7 +58,6 @@ module VCAP::CloudController::Metrics
7358 allow ( statsd_updater ) . to receive ( :update_user_count )
7459 allow ( statsd_updater ) . to receive ( :update_job_queue_length )
7560 allow ( statsd_updater ) . to receive ( :update_job_queue_load )
76- allow ( statsd_updater ) . to receive ( :update_thread_info_thin )
7761 allow ( statsd_updater ) . to receive ( :update_failed_job_count )
7862 allow ( statsd_updater ) . to receive ( :update_vitals )
7963 allow ( statsd_updater ) . to receive ( :update_log_counts )
@@ -83,14 +67,11 @@ module VCAP::CloudController::Metrics
8367 allow ( prometheus_updater ) . to receive ( :update_user_count )
8468 allow ( prometheus_updater ) . to receive ( :update_job_queue_length )
8569 allow ( prometheus_updater ) . to receive ( :update_job_queue_load )
86- allow ( prometheus_updater ) . to receive ( :update_thread_info_thin )
8770 allow ( prometheus_updater ) . to receive ( :update_failed_job_count )
8871 allow ( prometheus_updater ) . to receive ( :update_vitals )
8972 allow ( prometheus_updater ) . to receive ( :update_log_counts )
9073 allow ( prometheus_updater ) . to receive ( :update_task_stats )
9174 allow ( prometheus_updater ) . to receive ( :update_deploying_count )
92-
93- allow ( EventMachine ) . to receive ( :add_periodic_timer )
9475 end
9576
9677 it 'bumps the number of users and sets periodic timer' do
@@ -113,11 +94,6 @@ module VCAP::CloudController::Metrics
11394 periodic_updater . setup_updates
11495 end
11596
116- it 'updates thread count and event machine queues' do
117- expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
118- periodic_updater . setup_updates
119- end
120-
12197 it 'updates the vitals' do
12298 expect ( periodic_updater ) . to receive ( :update_vitals ) . once
12399 periodic_updater . setup_updates
@@ -138,15 +114,16 @@ module VCAP::CloudController::Metrics
138114 periodic_updater . setup_updates
139115 end
140116
141- context 'when EventMachine periodic_timer tasks are run' do
117+ context 'when Concurrent::TimerTasks are run' do
142118 before do
143119 @periodic_timers = [ ]
144120
145- allow ( EventMachine ) . to receive ( :add_periodic_timer ) do |interval , &block |
121+ allow ( Concurrent :: TimerTask ) . to receive ( :new ) do |opts , &block |
146122 @periodic_timers << {
147- interval :,
148- block :
123+ interval : opts [ :execution_interval ] ,
124+ block : block
149125 }
126+ double ( 'TimerTask' , execute : nil , shutdown : nil , kill : nil , running? : false )
150127 end
151128
152129 periodic_updater . setup_updates
@@ -176,44 +153,36 @@ module VCAP::CloudController::Metrics
176153 @periodic_timers [ 2 ] [ :block ] . call
177154 end
178155
179- it 'updates thread count and event machine queues' do
180- expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
181- expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
182- expect ( @periodic_timers [ 3 ] [ :interval ] ) . to eq ( 30 )
183-
184- @periodic_timers [ 3 ] [ :block ] . call
185- end
186-
187156 it 'bumps the length of cc failed job queues and sets periodic timer' do
188157 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
189158 expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
190- expect ( @periodic_timers [ 4 ] [ :interval ] ) . to eq ( 30 )
159+ expect ( @periodic_timers [ 3 ] [ :interval ] ) . to eq ( 30 )
191160
192- @periodic_timers [ 4 ] [ :block ] . call
161+ @periodic_timers [ 3 ] [ :block ] . call
193162 end
194163
195164 it 'updates the vitals' do
196165 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
197166 expect ( periodic_updater ) . to receive ( :update_vitals ) . once
198- expect ( @periodic_timers [ 5 ] [ :interval ] ) . to eq ( 30 )
167+ expect ( @periodic_timers [ 4 ] [ :interval ] ) . to eq ( 30 )
199168
200- @periodic_timers [ 5 ] [ :block ] . call
169+ @periodic_timers [ 4 ] [ :block ] . call
201170 end
202171
203172 it 'updates the log counts' do
204173 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
205174 expect ( periodic_updater ) . to receive ( :update_log_counts ) . once
206- expect ( @periodic_timers [ 6 ] [ :interval ] ) . to eq ( 30 )
175+ expect ( @periodic_timers [ 5 ] [ :interval ] ) . to eq ( 30 )
207176
208- @periodic_timers [ 6 ] [ :block ] . call
177+ @periodic_timers [ 5 ] [ :block ] . call
209178 end
210179
211180 it 'updates the task stats' do
212181 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
213182 expect ( periodic_updater ) . to receive ( :update_task_stats ) . once
214- expect ( @periodic_timers [ 7 ] [ :interval ] ) . to eq ( 30 )
183+ expect ( @periodic_timers [ 6 ] [ :interval ] ) . to eq ( 30 )
215184
216- @periodic_timers [ 7 ] [ :block ] . call
185+ @periodic_timers [ 6 ] [ :block ] . call
217186 end
218187 end
219188 end
@@ -538,75 +507,6 @@ module VCAP::CloudController::Metrics
538507 end
539508 end
540509
541- describe '#update_thread_info' do
542- before do
543- allow ( statsd_updater ) . to receive ( :update_thread_info_thin )
544- allow ( prometheus_updater ) . to receive ( :update_thread_info_thin )
545- end
546-
547- it 'contains EventMachine data and send it to all updaters' do
548- expected_thread_info = {
549- thread_count : Thread . list . size ,
550- event_machine : {
551- connection_count : 123 ,
552- threadqueue : {
553- size : 20 ,
554- num_waiting : 0
555- } ,
556- resultqueue : {
557- size : 0 ,
558- num_waiting : 1
559- }
560- }
561- }
562-
563- periodic_updater . update_thread_info
564-
565- expect ( statsd_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
566- expect ( prometheus_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
567- end
568-
569- context 'when resultqueue and/or threadqueue is not a queue' do
570- let ( :resultqueue ) { [ ] }
571- let ( :threadqueue ) { nil }
572-
573- it 'does not blow up' do
574- expected_thread_info = {
575- thread_count : Thread . list . size ,
576- event_machine : {
577- connection_count : 123 ,
578- threadqueue : {
579- size : 0 ,
580- num_waiting : 0
581- } ,
582- resultqueue : {
583- size : 0 ,
584- num_waiting : 0
585- }
586- }
587- }
588-
589- periodic_updater . update_thread_info
590-
591- expect ( statsd_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
592- expect ( prometheus_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
593- end
594- end
595-
596- context 'when Puma is configured as webserver' do
597- before do
598- TestConfig . override ( webserver : 'puma' )
599- end
600-
601- it 'does not send EventMachine data to updaters' do
602- periodic_updater . update_thread_info
603-
604- expect ( statsd_updater ) . not_to have_received ( :update_thread_info_thin )
605- expect ( prometheus_updater ) . not_to have_received ( :update_thread_info_thin )
606- end
607- end
608- end
609-
610510 describe '#update_vitals' do
611511 before do
612512 allow ( statsd_updater ) . to receive ( :update_vitals )
@@ -736,7 +636,6 @@ module VCAP::CloudController::Metrics
736636 expect ( periodic_updater ) . to receive ( :update_user_count ) . once
737637 expect ( periodic_updater ) . to receive ( :update_job_queue_length ) . once
738638 expect ( periodic_updater ) . to receive ( :update_job_queue_load ) . once
739- expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
740639 expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
741640 expect ( periodic_updater ) . to receive ( :update_vitals ) . once
742641 expect ( periodic_updater ) . to receive ( :update_log_counts ) . once
0 commit comments