8000 Use bound endpoint for server to avoid race condition. · Hanke/async-websocket@a63151d · GitHub
[go: up one dir, main page]

Skip to content

Commit a63151d

Browse files
committed
Use bound endpoint for server to avoid race condition.
1 parent b966d76 commit a63151d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

spec/async/websocket/server_examples.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@
2525
require 'async/http/server'
2626
require 'async/http/endpoint'
2727

28+
require 'async/io/shared_endpoint'
29+
2830
RSpec.shared_context Async::WebSocket::Server do
2931
include_context Async::RSpec::Reactor
3032

3133
let(:protocol) {described_class}
32-
let(:endpoint) {Async::HTTP::Endpoint.parse('http://127.0.0.1:8008')}
34+
let(:endpoint) {Async::HTTP::Endpoint.parse('http://127.0.0.1:8008', reuse_port: true)}
3335

34-
let!(:client) {Async::WebSocket::Client.open(endpoint, protocol: protocol)}
36+
let!(:bound_endpoint) {Async::IO::SharedEndpoint.bound(endpoint)}
37+
after{bound_endpoint.close}
38+
39+
let(:client) {Async::WebSocket::Client.open(endpoint, protocol: protocol)}
3540

3641
let!(:server_task) do
3742
reactor.async do
@@ -50,7 +55,7 @@
5055
let(:message) {["Hello World"]}
5156

5257
let(:server) do
53-
Async::HTTP::Server.for(endpoint, protocol: protocol) do |request|
58+
Async::HTTP::Server.for(bound_endpoint, protocol: protocol, scheme: endpoint.scheme) do |request|
5459
if Async::WebSocket::Request.websocket?(request)
5560
Async::WebSocket::Response.for(request, headers) do |stream|
5661
framer = Protocol::WebSocket::Framer.new(stream)
@@ -83,7 +88,7 @@
8388
let(:headers) {{"foo" => "bar"}}
8489

8590
let(:server) do
86-
Async::HTTP::Server.for(endpoint, protocol: protocol) do |request|
91+
Async::HTTP::Server.for(bound_endpoint, protocol: protocol, scheme: endpoint.scheme) do |request|
8792
if Async::WebSocket::Request.websocket?(request)
8893
Async::WebSocket::Response.for(request, headers) do |stream|
8994
framer = Protocol::WebSocket::Framer.new(stream)
@@ -112,4 +117,4 @@
112117
end
113118
end
114119
end
115-
end
120+
end

0 commit comments

Comments
 (0)
0