From 29234292e0f1b76c37b6ac9ae3edda34c8c25b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 17 Apr 2018 18:54:47 +0200 Subject: Add a Websocket test with 3000 connections To ensure the connections are not limited by max_connections. --- test/ws_SUITE.erl | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'test/ws_SUITE.erl') diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl index b86c595..81433fe 100644 --- a/test/ws_SUITE.erl +++ b/test/ws_SUITE.erl @@ -92,7 +92,7 @@ init_dispatch() -> autobahn_fuzzingclient(Config) -> doc("Autobahn test suite for the Websocket protocol."), Self = self(), - spawn_link(fun() -> start_port(Config, Self) end), + spawn_link(fun() -> do_start_port(Config, Self) end), receive autobahn_exit -> ok end, ct:log("

Full report

~n"), Report = config(priv_dir, Config) ++ "reports/servers/index.html", @@ -103,20 +103,47 @@ autobahn_fuzzingclient(Config) -> false -> ok end. -start_port(Config, Pid) -> +do_start_port(Config, Pid) -> Port = open_port({spawn, "wstest -m fuzzingclient -s " ++ config(data_dir, Config) ++ "client.json"}, [{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 {Port, {data, {eol, Line}}} -> io:format(user, "~s~n", [Line]), - receive_infinity(Port, Pid); + do_receive_infinity(Port, Pid); {Port, eof} -> Pid ! autobahn_exit 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) -> doc("Websocket version 0 (hixie-76 draft) is no longer supported."), {ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]), -- cgit v1.2.3