@@ -7,6 +7,7 @@ module VCAP::CloudController
77 let ( :periodic_updater ) { instance_double ( VCAP ::CloudController ::Metrics ::PeriodicUpdater ) }
88 let ( :request_metrics ) { instance_double ( VCAP ::CloudController ::Metrics ::RequestMetrics ) }
99 let ( :routing_api_client ) { instance_double ( VCAP ::CloudController ::RoutingApi ::Client , router_group_guid : '' ) }
10+ let ( :puma_server_double ) { instance_double ( Puma ::Server , add_tcp_listener : nil , add_unix_listener : nil , run : nil ) }
1011
1112 let ( :argv ) { [ ] }
1213
@@ -19,6 +20,7 @@ module VCAP::CloudController
1920 allow ( periodic_updater ) . to receive ( :setup_updates )
2021 allow ( VCAP ::PidFile ) . to receive ( :new ) { double ( :pidfile , unlink_at_exit : nil ) }
2122 allow_any_instance_of ( VCAP ::CloudController ::ThinRunner ) . to receive ( :start! )
23+ allow ( Puma ::Server ) . to receive ( :new ) . and_return ( puma_server_double )
2224 end
2325
2426 subject do
@@ -276,6 +278,66 @@ module VCAP::CloudController
276278 end
277279 end
278280 end
281+
282+ describe 'separate webserver for metrics' do
283+ context 'when the webserver is puma and nginx is used' do
284+ before do
285+ TestConfig . override ( nginx : { use_nginx : true } , webserver : 'puma' )
286+ allow ( Config ) . to receive ( :load_from_file ) . and_return ( TestConfig . config_instance )
287+ end
288+
289+ it 'sets up a separate webserver for metrics' do
290+ subject
291+
292+ expect ( Puma ::Server ) . to have_received ( :new ) . once
293+ end
294+
295+ it 'listens on the specified metrics port' do
296+ subject
297+
298+ expect ( puma_server_double ) . to have_received ( :add_tcp_listener ) . with ( '127.0.0.1' , 9395 )
299+ end
300+
301+ context 'metrics_socket is configured' do
302+ before do
303+ TestConfig . override ( nginx : { use_nginx : true , metrics_socket : '/tmp/puma_metrics.sock' } , webserver : 'puma' )
304+ allow ( Config ) . to receive ( :load_from_file ) . and_return ( TestConfig . config_instance )
305+ end
306+
307+ it 'listens on the specified metrics socket' do
308+ subject
309+
310+ expect ( puma_server_double ) . to have_received ( :add_unix_listener ) . with ( '/tmp/puma_metrics.sock' )
311+ end
312+ end
313+ end
314+
315+ context 'when the webserver is puma and nginx is not used' do
316+ before do
317+ TestConfig . override ( nginx : { use_nginx : false } , webserver : 'puma' )
318+ allow ( Config ) . to receive ( :load_from_file ) . and_return ( TestConfig . config_instance )
319+ end
320+
321+ it 'does not set up the webserver' do
322+ subject
323+
324+ expect ( Puma ::Server ) . not_to have_received ( :new )
325+ end
326+ end
327+
328+ context 'when the webserver is not puma' do
329+ before do
330+ TestConfig . override ( nginx : { use_nginx : true } , webserver : 'thin' )
331+ allow ( Config ) . to receive ( :load_from_file ) . and_return ( TestConfig . config_instance )
332+ end
333+
334+ it 'does not set up the webserver' do
335+ subject
336+
337+ expect ( Puma ::Server ) . not_to have_received ( :new )
338+ end
339+ end
340+ end
279341 end
280342 end
281343end
0 commit comments