From f22f53a71ef972684b7d8f9a18ee871467beed7d Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 9 Jun 2025 14:53:54 -0600 Subject: test: wait until the server is listening --- spec/support/server.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/support/server.rb b/spec/support/server.rb index 51d4ed8..e5acdd1 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require 'socket' RSpec.configure do |config| config.add_setting :http @@ -10,10 +11,21 @@ RSpec.configure do |config| config.add_setting :pid config.before :suite do + bind_addr = RSpec.configuration.bind_addr RSpec.configuration.pid = Process.spawn({ - "BIND_ADDR" => RSpec.configuration.bind_addr, + "BIND_ADDR" => bind_addr, }, "mise exec -- cargo run") - sleep 1 + + ip, port = bind_addr.split(":") + 10.times do |n| + begin + Socket.tcp(ip, port.to_i) { true } + break + rescue Errno::ECONNREFUSED => error + puts error.inspect + sleep 1 + end + end end config.after :suite do -- cgit v1.2.3