Skip to content

A platform for community discussion. Free, open, simple.

DEV: Prevent HTTP specs from hanging during server cleanup (#45219)

Alan Guo Xiang Tanefdaacf92b0c
diff --git a/spec/lib/final_destination/http_spec.rb b/spec/lib/final_destination/http_spec.rb
index 45f88bda929..b701c94b0e0 100644
--- a/spec/lib/final_destination/http_spec.rb
+++ b/spec/lib/final_destination/http_spec.rb
@@ -37,15 +37,18 @@ describe FinalDestination::HTTP do
# A minimal HTTP server on `bind`:<ephemeral> that answers every request with "hi".
def with_http_server(bind = "127.0.0.1")
+ started = Queue.new
server =
WEBrick::HTTPServer.new(
BindAddress: bind,
Port: 0,
Logger: WEBrick::Log.new(File::NULL),
AccessLog: [],
+ StartCallback: -> { started << true },
)
server.mount_proc("/") { |_req, res| res.body = "hi" }
thread = Thread.new { server.start }
+ started.pop
yield server.config[:Port]
ensure
server&.shutdown