Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

use next available port for webrick in httpx test

Ivan Kuchine2ee00e9ad8a
diff --git a/spec/httpx_spec.rb b/spec/httpx_spec.rb
index 7bb608bb09f..7390d68eb00 100644
--- a/spec/httpx_spec.rb
+++ b/spec/httpx_spec.rb
@@ -4,20 +4,21 @@ require "httpx"
RSpec.describe "HTTPX" do
describe "persistent connections" do
it "does not hang forever when used to request HTTP 1.1 server" do
- server = WEBrick::HTTPServer.new(Port: 8543)
+ server = WEBrick::HTTPServer.new(Port: 0)
server.mount_proc "/" do |_req, res|
res.body = "Response Body"
end
+ port = server.listeners[0].addr[1]
Thread.new { server.start }
session = HTTPX.plugin(:persistent).with(timeout: { keep_alive_timeout: 2 })
number_of_requests_made = 0
begin
Timeout.timeout(10) do
- session.post("http://localhost:8543")
+ session.post("http://localhost:#{port}")
number_of_requests_made += 1
sleep 4
- session.post("http://localhost:8543")
+ session.post("http://localhost:#{port}")
number_of_requests_made += 1
end
ensure