Skip to content

Commit

Permalink
Add a WS server test
Browse files Browse the repository at this point in the history
  • Loading branch information
EricForgy committed Feb 11, 2018
1 parent 3b027e3 commit f1e449c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/WebSockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,35 @@ for s in ["ws", "wss"]

end

@async HTTP.listen(ip"127.0.0.1",8000) do http
if HTTP.WebSockets.is_websocket_upgrade(http.message)
HTTP.WebSockets.upgrade(http) do client
data = ""
while !eof(client);
data = String(readavailable(client))
end
write(client,data)
end
end
end

sleep(2)

HTTP.WebSockets.open("ws://127.0.0.1:8000") do io
write(io, HTTP.bytes("Foo"))
@test !eof(io)
@test String(readavailable(io)) == "Foo"

write(io, HTTP.bytes("Hello"))
write(io, " There")
write(io, " World", "!")
closewrite(io)

buf = IOBuffer()
write(buf, io)
@test String(take!(buf)) == "Hello There World!"

close(io)
end

end # testset

0 comments on commit f1e449c

Please sign in to comment.