diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-09 14:53:54 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-09 14:53:54 -0600 |
| commit | f22f53a71ef972684b7d8f9a18ee871467beed7d (patch) | |
| tree | ad469a9661dfc5fb480ba9252ae0d7367a01e4f2 | |
| parent | 3ce95b474d2ee6c770a17a02318a6e01d9844b21 (diff) | |
test: wait until the server is listening
| -rw-r--r-- | spec/support/server.rb | 16 |
1 files changed, 14 insertions, 2 deletions
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 |
