From b4d08029a4bc309a17b07927b312d66120bf40c2 Mon Sep 17 00:00:00 2001 From: Jochen Ehret Date: Thu, 18 Dec 2025 13:24:56 +0100 Subject: [PATCH] Try to fix Errno::EADDRINUSE in metrics_spec * in the GitHub unit test action, we often see multiple errors "Address already in use - bind(2) for "127.0.0.1" port 9395" * try to use an ephemeral port for each test --- spec/request/internal/metrics_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/request/internal/metrics_spec.rb b/spec/request/internal/metrics_spec.rb index 62284d6b43d..221354c3c29 100644 --- a/spec/request/internal/metrics_spec.rb +++ b/spec/request/internal/metrics_spec.rb @@ -8,6 +8,10 @@ delegate :app, to: :metrics_webserver before do + # Force Puma to bind to an ephemeral port (0) to avoid EADDRINUSE + allow_any_instance_of(Puma::Server).to receive(:add_tcp_listener).and_wrap_original do |m, host, _| + m.call(host, 0) + end allow_any_instance_of(VCAP::CloudController::Metrics::PeriodicUpdater).to receive(:update_webserver_stats) metrics_webserver.start(TestConfig.config_instance) end