Skip to content

Commit 92c96c1

Browse files
committed
Use port 0 for automatically assigned ports.
1 parent 1508345 commit 92c96c1

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

lib/async/http/endpoint.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ def endpoint
177177
@endpoint ||= build_endpoint
178178
end
179179

180+
def endpoint=(endpoint)
181+
@endpoint = build_endpoint(endpoint)
182+
end
183+
180184
def bind(*arguments, &block)
181185
endpoint.bind(*arguments, &block)
182186
end

spec/async/http/body_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
context 'with echo server' do
2222
let(:server) do
23-
Async::HTTP::Server.for(server_endpoint, protocol: described_class) do |request|
23+
Async::HTTP::Server.for(@bound_endpoint, protocol: described_class) do |request|
2424
input = request.body
2525
output = Async::HTTP::Body::Writable.new
2626

@@ -55,7 +55,7 @@
5555
let(:notification) {Async::Notification.new}
5656

5757
let(:server) do
58-
Async::HTTP::Server.for(server_endpoint, protocol: described_class) do |request|
58+
Async::HTTP::Server.for(@bound_endpoint, protocol: described_class) do |request|
5959
body = Async::HTTP::Body::Writable.new
6060

6161
Async::Task.current.async do |task|
@@ -103,8 +103,8 @@
103103
let(:client_context) {authority.client_context}
104104

105105
# Shared port for localhost network tests.
106-
let(:server_endpoint) {Async::HTTP::Endpoint.parse("https://localhost:9299", ssl_context: server_context, reuse_port: true)}
107-
let(:client_endpoint) {Async::HTTP::Endpoint.parse("https://localhost:9299", ssl_context: client_context, reuse_port: true)}
106+
let(:server_endpoint) {Async::HTTP::Endpoint.parse("https://localhost:0", ssl_context: server_context, reuse_port: true)}
107+
let(:client_endpoint) {Async::HTTP::Endpoint.parse("https://localhost:0", ssl_context: client_context, reuse_port: true)}
108108

109109
it_should_behave_like Async::HTTP::Body
110110
end

spec/async/http/server_context.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
include_context Async::RSpec::Reactor
1313

1414
let(:protocol) {described_class}
15-
let(:endpoint) {Async::HTTP::Endpoint.parse('http://127.0.0.1:9294', timeout: 0.8, reuse_port: true, protocol: protocol)}
15+
let(:endpoint) {Async::HTTP::Endpoint.parse('http://127.0.0.1:0', timeout: 0.8, reuse_port: true, protocol: protocol)}
1616

1717
let(:server_endpoint) {endpoint}
1818
let(:client_endpoint) {endpoint}
@@ -37,8 +37,9 @@
3737
server.run
3838
end
3939

40-
@client = Async::HTTP::Client.new(client_endpoint, protocol: endpoint.protocol, retries: retries)
41-
end
40+
client_endpoint.endpoint = @bound_endpoint.local_address_endpoint
41+
@client = Async::HTTP::Client.new(client_endpoint, protocol: client_endpoint.protocol, retries: retries)
42+
end
4243

4344
after do
4445
@client&.close

0 commit comments

Comments
 (0)