diff options
author | Loïc Hoguin <[email protected]> | 2019-10-06 16:51:27 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-10-06 16:51:27 +0200 |
commit | 3977f2b96fb8cc2164bfe28ee094b3e661a2fad9 (patch) | |
tree | b709721f8f69a4ee87bbfab8359915bfd201bb10 /test | |
parent | 2b3852635115ad0aeeade9aeb88f285cfcd870b1 (diff) | |
download | cowboy-3977f2b96fb8cc2164bfe28ee094b3e661a2fad9.tar.gz cowboy-3977f2b96fb8cc2164bfe28ee094b3e661a2fad9.tar.bz2 cowboy-3977f2b96fb8cc2164bfe28ee094b3e661a2fad9.zip |
Document the commands based Websocket interface
The old interface with ok|reply|stop tuples is deprecated.
Diffstat (limited to 'test')
-rw-r--r-- | test/handlers/ws_deflate_opts_h.erl | 8 | ||||
-rw-r--r-- | test/handlers/ws_dont_validate_utf8_h.erl | 8 | ||||
-rw-r--r-- | test/handlers/ws_init_h.erl | 26 | ||||
-rw-r--r-- | test/ws_SUITE.erl | 7 | ||||
-rw-r--r-- | test/ws_SUITE_data/ws_echo.erl | 8 | ||||
-rw-r--r-- | test/ws_SUITE_data/ws_echo_timer.erl | 12 | ||||
-rw-r--r-- | test/ws_SUITE_data/ws_max_frame_size.erl | 12 | ||||
-rw-r--r-- | test/ws_SUITE_data/ws_send_many.erl | 6 | ||||
-rw-r--r-- | test/ws_SUITE_data/ws_timeout_cancel.erl | 6 |
9 files changed, 40 insertions, 53 deletions
diff --git a/test/handlers/ws_deflate_opts_h.erl b/test/handlers/ws_deflate_opts_h.erl index 1c15efe..b70110b 100644 --- a/test/handlers/ws_deflate_opts_h.erl +++ b/test/handlers/ws_deflate_opts_h.erl @@ -26,11 +26,11 @@ init(Req=#{qs := Qs}, State) -> }}. websocket_handle({text, Data}, State) -> - {reply, {text, Data}, State}; + {[{text, Data}], State}; websocket_handle({binary, Data}, State) -> - {reply, {binary, Data}, State}; + {[{binary, Data}], State}; websocket_handle(_, State) -> - {ok, State}. + {[], State}. websocket_info(_, State) -> - {ok, State}. + {[], State}. diff --git a/test/handlers/ws_dont_validate_utf8_h.erl b/test/handlers/ws_dont_validate_utf8_h.erl index 6599c78..27be6ad 100644 --- a/test/handlers/ws_dont_validate_utf8_h.erl +++ b/test/handlers/ws_dont_validate_utf8_h.erl @@ -13,11 +13,11 @@ init(Req, State) -> }}. websocket_handle({text, Data}, State) -> - {reply, {text, Data}, State}; + {[{text, Data}], State}; websocket_handle({binary, Data}, State) -> - {reply, {binary, Data}, State}; + {[{binary, Data}], State}; websocket_handle(_, State) -> - {ok, State}. + {[], State}. websocket_info(_, State) -> - {ok, State}. + {[], State}. diff --git a/test/handlers/ws_init_h.erl b/test/handlers/ws_init_h.erl index 08971ae..db5307b 100644 --- a/test/handlers/ws_init_h.erl +++ b/test/handlers/ws_init_h.erl @@ -18,30 +18,28 @@ websocket_init(State) -> do_websocket_init(State). do_websocket_init(State=ok) -> - {ok, State}; + {[], State}; do_websocket_init(State=ok_hibernate) -> - {ok, State, hibernate}; + {[], State, hibernate}; do_websocket_init(State=reply) -> - {reply, {text, "Hello"}, State}; + {[{text, "Hello"}], State}; do_websocket_init(State=reply_hibernate) -> - {reply, {text, "Hello"}, State, hibernate}; + {[{text, "Hello"}], State, hibernate}; do_websocket_init(State=reply_close) -> - {reply, close, State}; + {[close], State}; do_websocket_init(State=reply_close_hibernate) -> - {reply, close, State, hibernate}; + {[close], State, hibernate}; do_websocket_init(State=reply_many) -> - {reply, [{text, "Hello"}, {binary, "World"}], State}; + {[{text, "Hello"}, {binary, "World"}], State}; do_websocket_init(State=reply_many_hibernate) -> - {reply, [{text, "Hello"}, {binary, "World"}], State, hibernate}; + {[{text, "Hello"}, {binary, "World"}], State, hibernate}; do_websocket_init(State=reply_many_close) -> - {reply, [{text, "Hello"}, close], State}; + {[{text, "Hello"}, close], State}; do_websocket_init(State=reply_many_close_hibernate) -> - {reply, [{text, "Hello"}, close], State, hibernate}; -do_websocket_init(State=stop) -> - {stop, State}. + {[{text, "Hello"}, close], State, hibernate}. websocket_handle(_, State) -> - {ok, State}. + {[], State}. websocket_info(_, State) -> - {ok, State}. + {[], State}. diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl index 64b8561..37f4012 100644 --- a/test/ws_SUITE.erl +++ b/test/ws_SUITE.erl @@ -403,13 +403,6 @@ ws_init_return_reply_many_close_hibernate(Config) -> 1:1, 0:3, 8:4, 0:8 >>} = gen_tcp:recv(Socket, 9, 6000), ok. -ws_init_return_stop(Config) -> - doc("Handler closes immediately after the handshake."), - {ok, Socket, _} = do_handshake("/ws_init?stop", Config), - {ok, << 1:1, 0:3, 8:4, 0:1, 2:7, 1000:16 >>} = gen_tcp:recv(Socket, 0, 6000), - {error, closed} = gen_tcp:recv(Socket, 0, 6000), - ok. - ws_init_shutdown_before_handshake(Config) -> doc("Handler stops before Websocket handshake."), {ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]), diff --git a/test/ws_SUITE_data/ws_echo.erl b/test/ws_SUITE_data/ws_echo.erl index a94b4c0..efdc204 100644 --- a/test/ws_SUITE_data/ws_echo.erl +++ b/test/ws_SUITE_data/ws_echo.erl @@ -12,11 +12,11 @@ init(Req, _) -> }}. websocket_handle({text, Data}, State) -> - {reply, {text, Data}, State}; + {[{text, Data}], State}; websocket_handle({binary, Data}, State) -> - {reply, {binary, Data}, State}; + {[{binary, Data}], State}; websocket_handle(_Frame, State) -> - {ok, State}. + {[], State}. websocket_info(_Info, State) -> - {ok, State}. + {[], State}. diff --git a/test/ws_SUITE_data/ws_echo_timer.erl b/test/ws_SUITE_data/ws_echo_timer.erl index 7f37229..8157af3 100644 --- a/test/ws_SUITE_data/ws_echo_timer.erl +++ b/test/ws_SUITE_data/ws_echo_timer.erl @@ -12,17 +12,17 @@ init(Req, _) -> websocket_init(State) -> erlang:start_timer(1000, self(), <<"websocket_init">>), - {ok, State}. + {[], State}. websocket_handle({text, Data}, State) -> - {reply, {text, Data}, State}; + {[{text, Data}], State}; websocket_handle({binary, Data}, State) -> - {reply, {binary, Data}, State}; + {[{binary, Data}], State}; websocket_handle(_Frame, State) -> - {ok, State}. + {[], State}. websocket_info({timeout, _Ref, Msg}, State) -> erlang:start_timer(1000, self(), <<"websocket_handle">>), - {reply, {text, Msg}, State}; + {[{text, Msg}], State}; websocket_info(_Info, State) -> - {ok, State}. + {[], State}. diff --git a/test/ws_SUITE_data/ws_max_frame_size.erl b/test/ws_SUITE_data/ws_max_frame_size.erl index 2d34218..3d81497 100644 --- a/test/ws_SUITE_data/ws_max_frame_size.erl +++ b/test/ws_SUITE_data/ws_max_frame_size.erl @@ -1,22 +1,18 @@ -module(ws_max_frame_size). -export([init/2]). --export([websocket_init/1]). -export([websocket_handle/2]). -export([websocket_info/2]). init(Req, State) -> {cowboy_websocket, Req, State, #{max_frame_size => 8}}. -websocket_init(State) -> - {ok, State}. - websocket_handle({text, Data}, State) -> - {reply, {text, Data}, State}; + {[{text, Data}], State}; websocket_handle({binary, Data}, State) -> - {reply, {binary, Data}, State}; + {[{binary, Data}], State}; websocket_handle(_Frame, State) -> - {ok, State}. + {[], State}. websocket_info(_Info, State) -> - {ok, State}. + {[], State}. diff --git a/test/ws_SUITE_data/ws_send_many.erl b/test/ws_SUITE_data/ws_send_many.erl index d621a3d..2f6437f 100644 --- a/test/ws_SUITE_data/ws_send_many.erl +++ b/test/ws_SUITE_data/ws_send_many.erl @@ -12,10 +12,10 @@ init(Req, Opts) -> websocket_init(State) -> erlang:send_after(10, self(), send_many), - {ok, State}. + {[], State}. websocket_handle(_Frame, State) -> - {ok, State}. + {[], State}. websocket_info(send_many, State = [{sequence, Sequence}]) -> - {reply, Sequence, State}. + {Sequence, State}. diff --git a/test/ws_SUITE_data/ws_timeout_cancel.erl b/test/ws_SUITE_data/ws_timeout_cancel.erl index 587f2c5..481d5e6 100644 --- a/test/ws_SUITE_data/ws_timeout_cancel.erl +++ b/test/ws_SUITE_data/ws_timeout_cancel.erl @@ -13,10 +13,10 @@ init(Req, _) -> }}. websocket_handle({text, Data}, State) -> - {reply, {text, Data}, State}; + {[{text, Data}], State}; websocket_handle({binary, Data}, State) -> - {reply, {binary, Data}, State}. + {[{binary, Data}], State}. websocket_info(_Info, State) -> erlang:start_timer(500, self(), should_not_cancel_timer), - {ok, State}. + {[], State}. |