mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Add a Websocket test with 3000 connections
To ensure the connections are not limited by max_connections.
This commit is contained in:
parent
7c366986d5
commit
29234292e0
1 changed files with 32 additions and 5 deletions
|
@ -92,7 +92,7 @@ init_dispatch() ->
|
||||||
autobahn_fuzzingclient(Config) ->
|
autobahn_fuzzingclient(Config) ->
|
||||||
doc("Autobahn test suite for the Websocket protocol."),
|
doc("Autobahn test suite for the Websocket protocol."),
|
||||||
Self = self(),
|
Self = self(),
|
||||||
spawn_link(fun() -> start_port(Config, Self) end),
|
spawn_link(fun() -> do_start_port(Config, Self) end),
|
||||||
receive autobahn_exit -> ok end,
|
receive autobahn_exit -> ok end,
|
||||||
ct:log("<h2><a href=\"log_private/reports/servers/index.html\">Full report</a></h2>~n"),
|
ct:log("<h2><a href=\"log_private/reports/servers/index.html\">Full report</a></h2>~n"),
|
||||||
Report = config(priv_dir, Config) ++ "reports/servers/index.html",
|
Report = config(priv_dir, Config) ++ "reports/servers/index.html",
|
||||||
|
@ -103,20 +103,47 @@ autobahn_fuzzingclient(Config) ->
|
||||||
false -> ok
|
false -> ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
start_port(Config, Pid) ->
|
do_start_port(Config, Pid) ->
|
||||||
Port = open_port({spawn, "wstest -m fuzzingclient -s " ++ config(data_dir, Config) ++ "client.json"},
|
Port = open_port({spawn, "wstest -m fuzzingclient -s " ++ config(data_dir, Config) ++ "client.json"},
|
||||||
[{line, 10000}, {cd, config(priv_dir, Config)}, binary, eof]),
|
[{line, 10000}, {cd, config(priv_dir, Config)}, binary, eof]),
|
||||||
receive_infinity(Port, Pid).
|
do_receive_infinity(Port, Pid).
|
||||||
|
|
||||||
receive_infinity(Port, Pid) ->
|
do_receive_infinity(Port, Pid) ->
|
||||||
receive
|
receive
|
||||||
{Port, {data, {eol, Line}}} ->
|
{Port, {data, {eol, Line}}} ->
|
||||||
io:format(user, "~s~n", [Line]),
|
io:format(user, "~s~n", [Line]),
|
||||||
receive_infinity(Port, Pid);
|
do_receive_infinity(Port, Pid);
|
||||||
{Port, eof} ->
|
{Port, eof} ->
|
||||||
Pid ! autobahn_exit
|
Pid ! autobahn_exit
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
unlimited_connections(Config) ->
|
||||||
|
doc("Websocket connections are not limited. The connections "
|
||||||
|
"are removed from the count after the handshake completes."),
|
||||||
|
_ = [begin
|
||||||
|
spawn_link(fun() -> do_connect_and_loop(Config) end),
|
||||||
|
timer:sleep(1)
|
||||||
|
end || _ <- lists:seq(1, 3000)],
|
||||||
|
timer:sleep(1000),
|
||||||
|
%% We have at least 3000 client and 3000 server sockets.
|
||||||
|
true = length(erlang:ports()) > 6000,
|
||||||
|
%% Ranch thinks we have no connections.
|
||||||
|
0 = ranch_server:count_connections(ws),
|
||||||
|
ok.
|
||||||
|
|
||||||
|
do_connect_and_loop(Config) ->
|
||||||
|
{ok, Socket, _} = do_handshake("/ws_echo", Config),
|
||||||
|
do_loop(Socket).
|
||||||
|
|
||||||
|
do_loop(Socket) ->
|
||||||
|
%% Masked text hello echoed back clear by the server.
|
||||||
|
Mask = 16#37fa213d,
|
||||||
|
MaskedHello = do_mask(<<"Hello">>, Mask, <<>>),
|
||||||
|
ok = gen_tcp:send(Socket, << 1:1, 0:3, 1:4, 1:1, 5:7, Mask:32, MaskedHello/binary >>),
|
||||||
|
{ok, << 1:1, 0:3, 1:4, 0:1, 5:7, "Hello" >>} = gen_tcp:recv(Socket, 0, 6000),
|
||||||
|
timer:sleep(1000),
|
||||||
|
do_loop(Socket).
|
||||||
|
|
||||||
ws0(Config) ->
|
ws0(Config) ->
|
||||||
doc("Websocket version 0 (hixie-76 draft) is no longer supported."),
|
doc("Websocket version 0 (hixie-76 draft) is no longer supported."),
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue