Skip to content

Commit

Permalink
Test websocket server
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcaine committed Dec 10, 2020
1 parent fba4f3b commit ce32c3b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,28 @@ rm(path)
# Test you can pass the string last if you really want.
@test page(identity, "") isa Function
@test route(identity, "") isa Function

@testset "WebSockets" begin
import Mux.WebSockets

@app h = (
Mux.defaults,
page("/", respond("<h1>Hello World!</h1>")),
Mux.notfound());

@app w = (
Mux.wdefaults,
route("/ws_io", Mux.echo),
Mux.wclose,
Mux.notfound());

serve(h, w, 2333)

WebSockets.open("ws://localhost:2333/ws_io") do ws_client
message = "Hello WebSocket!"
WebSockets.writeguarded(ws_client, message)
data, success = WebSockets.readguarded(ws_client)
@test success
@test String(data) == message
end
end

0 comments on commit ce32c3b

Please sign in to comment.