Skip to content

Commit 55daf00

Browse files
authored
Don't start the MetricsWebserver when not really needed (#4717)
The tests only check if the config is applied correctly, thus we don't need to start a real webserver. This (hopefully) prevents issues with ports already being in use.
1 parent 2a57ab5 commit 55daf00

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

spec/unit/lib/cloud_controller/metrics_webserver_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
module VCAP::CloudController
44
RSpec.describe MetricsWebserver do
55
let(:metrics_webserver) { described_class.new }
6+
let(:puma_server_double) { instance_double(Puma::Server, add_tcp_listener: nil, add_unix_listener: nil, run: nil) }
67
let(:config) { double('config', get: nil) }
78

8-
after do
9-
metrics_webserver.stop
9+
before do
10+
allow(Puma::Server).to receive(:new).and_return(puma_server_double)
1011
end
1112

1213
describe '#start' do
1314
it 'configures and starts a Puma server' do
14-
allow(Puma::Server).to receive(:new).and_call_original
15-
expect_any_instance_of(Puma::Server).to receive(:run)
15+
expect(puma_server_double).to receive(:run)
1616

1717
metrics_webserver.start(config)
18+
19+
expect(Puma::Server).to have_received(:new).with(an_instance_of(Rack::Builder))
1820
end
1921

2022
context 'when no socket is specified' do
@@ -23,7 +25,7 @@ module VCAP::CloudController
2325
end
2426

2527
it 'uses a TCP listener' do
26-
expect_any_instance_of(Puma::Server).to receive(:add_tcp_listener).with('127.0.0.1', 9395)
28+
expect(puma_server_double).to receive(:add_tcp_listener).with('127.0.0.1', 9395)
2729

2830
metrics_webserver.start(config)
2931
end
@@ -35,7 +37,7 @@ module VCAP::CloudController
3537
end
3638

3739
it 'uses a Unix socket listener' do
38-
expect_any_instance_of(Puma::Server).to receive(:add_unix_listener).with('/tmp/metrics.sock')
40+
expect(puma_server_double).to receive(:add_unix_listener).with('/tmp/metrics.sock')
3941

4042
metrics_webserver.start(config)
4143
end

0 commit comments

Comments
 (0)