mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Use gun:ws_send/3 in tests
This commit is contained in:
parent
e12d7bbe21
commit
fa9c8ad832
2 changed files with 15 additions and 15 deletions
|
@ -458,14 +458,14 @@ websocket(Config) ->
|
||||||
exit(timeout)
|
exit(timeout)
|
||||||
end,
|
end,
|
||||||
%% Check that we receive the echoed message.
|
%% Check that we receive the echoed message.
|
||||||
gun:ws_send(Pid, {text, <<"hello">>}),
|
gun:ws_send(Pid, StreamRef, {text, <<"hello">>}),
|
||||||
receive
|
receive
|
||||||
{gun_ws, Pid, StreamRef, {text, <<"That's what she said! hello">>}} ->
|
{gun_ws, Pid, StreamRef, {text, <<"That's what she said! hello">>}} ->
|
||||||
ok
|
ok
|
||||||
after 500 ->
|
after 500 ->
|
||||||
exit(timeout)
|
exit(timeout)
|
||||||
end,
|
end,
|
||||||
gun:ws_send(Pid, close)
|
gun:ws_send(Pid, StreamRef, close)
|
||||||
after
|
after
|
||||||
do_stop(websocket)
|
do_stop(websocket)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -82,9 +82,9 @@ receive_ws(ConnPid, StreamRef) ->
|
||||||
{error, timeout}
|
{error, timeout}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
ensure_handle_is_called(ConnPid, "/handle") ->
|
ensure_handle_is_called(ConnPid, StreamRef, "/handle") ->
|
||||||
gun:ws_send(ConnPid, {text, <<"Necessary to trigger websocket_handle/2.">>});
|
gun:ws_send(ConnPid, StreamRef, {text, <<"Necessary to trigger websocket_handle/2.">>});
|
||||||
ensure_handle_is_called(_, _) ->
|
ensure_handle_is_called(_, _, _) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% Tests.
|
%% Tests.
|
||||||
|
@ -103,7 +103,7 @@ websocket_info_nothing(Config) ->
|
||||||
|
|
||||||
do_nothing(Config, Path) ->
|
do_nothing(Config, Path) ->
|
||||||
{ok, ConnPid, StreamRef} = gun_open_ws(Config, Path, []),
|
{ok, ConnPid, StreamRef} = gun_open_ws(Config, Path, []),
|
||||||
ensure_handle_is_called(ConnPid, Path),
|
ensure_handle_is_called(ConnPid, StreamRef, Path),
|
||||||
{error, timeout} = receive_ws(ConnPid, StreamRef),
|
{error, timeout} = receive_ws(ConnPid, StreamRef),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ websocket_info_invalid(Config) ->
|
||||||
do_invalid(Config, "/info").
|
do_invalid(Config, "/info").
|
||||||
|
|
||||||
do_invalid(Config, Path) ->
|
do_invalid(Config, Path) ->
|
||||||
{ok, ConnPid, _} = gun_open_ws(Config, Path, bad),
|
{ok, ConnPid, StreamRef} = gun_open_ws(Config, Path, bad),
|
||||||
ensure_handle_is_called(ConnPid, Path),
|
ensure_handle_is_called(ConnPid, StreamRef, Path),
|
||||||
gun_down(ConnPid).
|
gun_down(ConnPid).
|
||||||
|
|
||||||
websocket_init_one_frame(Config) ->
|
websocket_init_one_frame(Config) ->
|
||||||
|
@ -140,7 +140,7 @@ do_one_frame(Config, Path) ->
|
||||||
{ok, ConnPid, StreamRef} = gun_open_ws(Config, Path, [
|
{ok, ConnPid, StreamRef} = gun_open_ws(Config, Path, [
|
||||||
{text, <<"One frame!">>}
|
{text, <<"One frame!">>}
|
||||||
]),
|
]),
|
||||||
ensure_handle_is_called(ConnPid, Path),
|
ensure_handle_is_called(ConnPid, StreamRef, Path),
|
||||||
{ok, {text, <<"One frame!">>}} = receive_ws(ConnPid, StreamRef),
|
{ok, {text, <<"One frame!">>}} = receive_ws(ConnPid, StreamRef),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ do_many_frames(Config, Path) ->
|
||||||
{text, <<"One frame!">>},
|
{text, <<"One frame!">>},
|
||||||
{binary, <<"Two frames!">>}
|
{binary, <<"Two frames!">>}
|
||||||
]),
|
]),
|
||||||
ensure_handle_is_called(ConnPid, Path),
|
ensure_handle_is_called(ConnPid, StreamRef, Path),
|
||||||
{ok, {text, <<"One frame!">>}} = receive_ws(ConnPid, StreamRef),
|
{ok, {text, <<"One frame!">>}} = receive_ws(ConnPid, StreamRef),
|
||||||
{ok, {binary, <<"Two frames!">>}} = receive_ws(ConnPid, StreamRef),
|
{ok, {binary, <<"Two frames!">>}} = receive_ws(ConnPid, StreamRef),
|
||||||
ok.
|
ok.
|
||||||
|
@ -180,7 +180,7 @@ websocket_info_close_frame(Config) ->
|
||||||
|
|
||||||
do_close_frame(Config, Path) ->
|
do_close_frame(Config, Path) ->
|
||||||
{ok, ConnPid, StreamRef} = gun_open_ws(Config, Path, [close]),
|
{ok, ConnPid, StreamRef} = gun_open_ws(Config, Path, [close]),
|
||||||
ensure_handle_is_called(ConnPid, Path),
|
ensure_handle_is_called(ConnPid, StreamRef, Path),
|
||||||
{ok, close} = receive_ws(ConnPid, StreamRef),
|
{ok, close} = receive_ws(ConnPid, StreamRef),
|
||||||
gun_down(ConnPid).
|
gun_down(ConnPid).
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ do_many_frames_then_close_frame(Config, Path) ->
|
||||||
{binary, <<"Two frames!">>},
|
{binary, <<"Two frames!">>},
|
||||||
close
|
close
|
||||||
]),
|
]),
|
||||||
ensure_handle_is_called(ConnPid, Path),
|
ensure_handle_is_called(ConnPid, StreamRef, Path),
|
||||||
{ok, {text, <<"One frame!">>}} = receive_ws(ConnPid, StreamRef),
|
{ok, {text, <<"One frame!">>}} = receive_ws(ConnPid, StreamRef),
|
||||||
{ok, {binary, <<"Two frames!">>}} = receive_ws(ConnPid, StreamRef),
|
{ok, {binary, <<"Two frames!">>}} = receive_ws(ConnPid, StreamRef),
|
||||||
{ok, close} = receive_ws(ConnPid, StreamRef),
|
{ok, close} = receive_ws(ConnPid, StreamRef),
|
||||||
|
@ -215,7 +215,7 @@ websocket_active_false(Config) ->
|
||||||
doc("The {active, false} command stops receiving data from the socket. "
|
doc("The {active, false} command stops receiving data from the socket. "
|
||||||
"The {active, true} command reenables it."),
|
"The {active, true} command reenables it."),
|
||||||
{ok, ConnPid, StreamRef} = gun_open_ws(Config, "/active", []),
|
{ok, ConnPid, StreamRef} = gun_open_ws(Config, "/active", []),
|
||||||
gun:ws_send(ConnPid, {text, <<"Not received until the handler enables active again.">>}),
|
gun:ws_send(ConnPid, StreamRef, {text, <<"Not received until the handler enables active again.">>}),
|
||||||
{error, timeout} = receive_ws(ConnPid, StreamRef),
|
{error, timeout} = receive_ws(ConnPid, StreamRef),
|
||||||
{ok, {text, <<"Not received until the handler enables active again.">>}}
|
{ok, {text, <<"Not received until the handler enables active again.">>}}
|
||||||
= receive_ws(ConnPid, StreamRef),
|
= receive_ws(ConnPid, StreamRef),
|
||||||
|
@ -255,7 +255,7 @@ websocket_deflate_ignore_if_not_negotiated(Config) ->
|
||||||
"when compression was not negotiated."),
|
"when compression was not negotiated."),
|
||||||
{ok, ConnPid, StreamRef} = gun_open_ws(Config, "/deflate", []),
|
{ok, ConnPid, StreamRef} = gun_open_ws(Config, "/deflate", []),
|
||||||
_ = [begin
|
_ = [begin
|
||||||
gun:ws_send(ConnPid, {text, <<"Hello.">>}),
|
gun:ws_send(ConnPid, StreamRef, {text, <<"Hello.">>}),
|
||||||
{ok, {text, <<"Hello.">>}} = receive_ws(ConnPid, StreamRef)
|
{ok, {text, <<"Hello.">>}} = receive_ws(ConnPid, StreamRef)
|
||||||
end || _ <- lists:seq(1, 10)],
|
end || _ <- lists:seq(1, 10)],
|
||||||
ok.
|
ok.
|
||||||
|
@ -280,7 +280,7 @@ websocket_set_options_idle_timeout(Config) ->
|
||||||
{error, timeout} = gun:await(ConnPid, StreamRef, 2000),
|
{error, timeout} = gun:await(ConnPid, StreamRef, 2000),
|
||||||
%% Trigger the change in idle_timeout and confirm that
|
%% Trigger the change in idle_timeout and confirm that
|
||||||
%% the connection gets closed soon after.
|
%% the connection gets closed soon after.
|
||||||
gun:ws_send(ConnPid, {text, <<"idle_timeout_short">>}),
|
gun:ws_send(ConnPid, StreamRef, {text, <<"idle_timeout_short">>}),
|
||||||
receive
|
receive
|
||||||
{gun_down, ConnPid, _, _, _} ->
|
{gun_down, ConnPid, _, _, _} ->
|
||||||
ok
|
ok
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue