@@ -48,7 +48,7 @@ tasks that you will try to start.
4848 # define filewatcher outside so that can follow it
4949 fw = LS. SimpleWatcher (LS. file_changed_callback)
5050 task = @spawn serve (fw; port= port)
51- sleep ( 0.1 ) # give it time to get started
51+ timedwait (() -> LS . is_running (fw), 10 ) # give it time to get started
5252
5353 # there should be a callback associated with fw now
5454 @test fw. status == :runnable
@@ -97,19 +97,17 @@ tasks that you will try to start.
9797 # and then subsequently close a websocket. We check this happens properly by adding
9898 # our own sentinel websocket
9999 function makews ()
100- req = HTTP. Request ()
101- return HTTP. WebSockets. WebSocket (
102- HTTP. Connection (IOBuffer ()), req, req. response; client= false
103- )
100+ io = IOBuffer (UInt8[], read= true , write= true )
101+ return HTTP. WebSockets. WebSocket (io, () -> nothing ; is_client= false )
104102 end
105103 sentinel = makews ()
106104 LS. WS_VIEWERS[" tmp.html" ] = [sentinel]
107105
108- @test sentinel. io . io . writable
106+ @test ! sentinel. writeclosed
109107 write (" tmp.html" , " something new" )
110108 sleep (0.5 )
111109 # the sentinel websocket should be closed
112- @test ! sentinel. io . io . writable
110+ @test sentinel. writeclosed
113111 # the websockets should have been flushed
114112 @test isempty (LS. WS_VIEWERS[" tmp.html" ])
115113
@@ -121,8 +119,8 @@ tasks that you will try to start.
121119 write (" css/foo.css" , " body { color:blue; }" )
122120 sleep (0.5 )
123121 # all sentinel websockets should be closed
124- @test ! sentinel1. io . io . writable
125- @test ! sentinel2. io . io . writable
122+ @test sentinel1. writeclosed
123+ @test sentinel2. writeclosed
126124
127125 # Mimic an error when building documentation with Documenter.jl. When this
128126 # happens servedocs_callback!() will set the watcher status to
@@ -174,27 +172,24 @@ end
174172 cd (mktempdir ())
175173 write (" test_file.html" , " Hello!" )
176174
177- server = Sockets. listen (Sockets. localhost, 8001 )
178- io = Sockets. connect (Sockets. localhost, 8001 )
179- key = " k5zQsAMXfFlvmWIE/YCiEg=="
180- s = HTTP. Stream (
181- HTTP. Request (
182- " GET" ,
183- " http://localhost:8562/test_file.html" ,
184- [
185- " Connection" => " upgrade" ,
186- " Upgrade" => " websocket" ,
187- " Sec-WebSocket-Key" => key,
188- " Sec-WebSocket-Version" => " 13"
189- ]
190- ),
191- HTTP. Connection (io)
192- )
193-
194- fs_path, _ = LS. get_fs_path (s. message. target)
175+ target = " /test_file.html"
176+ fs_path, _ = LS. get_fs_path (target)
195177 @test fs_path == " test_file.html"
196178
197- tsk = @spawn LS. HTTP. WebSockets. upgrade (LS. ws_tracker, s)
179+ function make_tracking_ws (tgt)
180+ io = IOBuffer (UInt8[], read= true , write= true )
181+ ws = HTTP. WebSockets. WebSocket (io, () -> nothing ; is_client= false )
182+ ws. handshake_request = HTTP. Request (" GET" , tgt, [
183+ " Connection" => " upgrade" ,
184+ " Upgrade" => " websocket" ,
185+ " Sec-WebSocket-Key" => " k5zQsAMXfFlvmWIE/YCiEg==" ,
186+ " Sec-WebSocket-Version" => " 13"
187+ ])
188+ return ws
189+ end
190+
191+ ws1 = make_tracking_ws (target)
192+ tsk = @spawn LS. ws_tracker (ws1)
198193 sleep (1.0 )
199194 # the websocket should have been added to the list
200195 @test LS. WS_VIEWERS[fs_path] isa Vector{HTTP. WebSockets. WebSocket}
207202 @test istaskdone (tsk)
208203 @test ! LS. WS_INTERRUPT[]
209204
210- io = Sockets. connect (Sockets. localhost, 8001 )
211- key = " k5zQsAMXfFlvmWIE/YCiEg=="
212- s = HTTP. Stream (
213- HTTP. Request (
214- " GET" ,
215- " http://localhost:8562/test_file.html" ,
216- [
217- " Connection" => " upgrade" ,
218- " Upgrade" => " websocket" ,
219- " Sec-WebSocket-Key" => key,
220- " Sec-WebSocket-Version" => " 13"
221- ]
222- ),
223- HTTP. Connection (io)
224- )
225-
226- tsk = @spawn LS. HTTP. WebSockets. upgrade (LS. ws_tracker, s)
205+ ws2 = make_tracking_ws (target)
206+ tsk = @spawn LS. ws_tracker (ws2)
227207 sleep (1.0 )
228208
229209 # simulate a "bad" closure
235215 @test length (LS. WS_VIEWERS[fs_path]) == 2
236216
237217 # cleanup
238- close (server)
239218 empty! (LS. WS_VIEWERS)
240219
241220 cd (bk)
0 commit comments