diff options
author | Loïc Hoguin <[email protected]> | 2019-09-24 19:18:35 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-09-24 19:28:48 +0200 |
commit | d9a970be90d0105af215531d74809878f9c21338 (patch) | |
tree | eb891e8c9373dee9f7353a9920aaf25f6b2f2570 /test | |
parent | a18ca0ae8ff76594c7b629f4340adab0a30954c4 (diff) | |
download | gun-d9a970be90d0105af215531d74809878f9c21338.tar.gz gun-d9a970be90d0105af215531d74809878f9c21338.tar.bz2 gun-d9a970be90d0105af215531d74809878f9c21338.zip |
Add auto-ping to Websocket and a silence_pings option
The auto-ping will at regular interval send a ping frame.
The silence_pings option defaults to true. It can be set
to false when the user needs to receive ping/pong frames.
Diffstat (limited to 'test')
-rw-r--r-- | test/ws_SUITE.erl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl index 4d2387b..55cdfba 100644 --- a/test/ws_SUITE.erl +++ b/test/ws_SUITE.erl @@ -80,6 +80,33 @@ error_http_request(Config) -> {error, {connection_error, {badstate, _}}} = gun:await(ConnPid, StreamRef2), gun:close(ConnPid). +keepalive(Config) -> + doc("Ensure that Gun automatically sends ping frames."), + {ok, ConnPid} = gun:open("localhost", config(port, Config), #{ + ws_opts => #{ + keepalive => 100, + silence_pings => false + } + }), + {ok, _} = gun:await_up(ConnPid), + StreamRef = gun:ws_upgrade(ConnPid, "/", []), + {upgrade, [<<"websocket">>], _} = gun:await(ConnPid, StreamRef), + %% Gun sent a ping automatically, we therefore receive a pong. + {ws, pong} = gun:await(ConnPid, StreamRef), + gun:close(ConnPid). + +keepalive_default_silence_pings(Config) -> + doc("Ensure that Gun does not forward ping/pong by default."), + {ok, ConnPid} = gun:open("localhost", config(port, Config), #{ + ws_opts => #{keepalive => 100} + }), + {ok, _} = gun:await_up(ConnPid), + StreamRef = gun:ws_upgrade(ConnPid, "/", []), + {upgrade, [<<"websocket">>], _} = gun:await(ConnPid, StreamRef), + %% Gun sent a ping automatically, but we silence ping/pong by default. + {error, timeout} = gun:await(ConnPid, StreamRef, 1000), + gun:close(ConnPid). + reject_upgrade(Config) -> doc("Ensure Websocket connections can be rejected."), {ok, ConnPid} = gun:open("localhost", config(port, Config)), |