25
25
require 'async/http/server'
26
26
require 'async/http/endpoint'
27
27
28
+ require 'async/io/shared_endpoint'
29
+
28
30
RSpec . shared_context Async ::WebSocket ::Server do
29
31
include_context Async ::RSpec ::Reactor
30
32
31
33
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 ) }
33
35
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 ) }
35
40
36
41
let! ( :server_task ) do
37
42
reactor . async do
50
55
let ( :message ) { [ "Hello World" ] }
51
56
52
57
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 |
54
59
if Async ::WebSocket ::Request . websocket? ( request )
55
60
Async ::WebSocket ::Response . for ( request , headers ) do |stream |
56
61
framer = Protocol ::WebSocket ::Framer . new ( stream )
83
88
let ( :headers ) { { "foo" => "bar" } }
84
89
85
90
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 |
87
92
if Async ::WebSocket ::Request . websocket? ( request )
88
93
Async ::WebSocket ::Response . for ( request , headers ) do |stream |
89
94
framer = Protocol ::WebSocket ::Framer . new ( stream )
112
117
end
113
118
end
114
119
end
115
- end
120
+ end
0 commit comments