Browse Source

Fix many conns_sups tests for Windows

juhlig 5 years ago
parent
commit
8436e96544
2 changed files with 13 additions and 12 deletions
  1. 7 7
      test/acceptor_SUITE.erl
  2. 6 5
      test/notify_and_wait_protocol.erl

+ 7 - 7
test/acceptor_SUITE.erl

@@ -916,7 +916,7 @@ tcp_max_connections(_) ->
 	Name = name(),
 	{ok, _} = ranch:start_listener(Name,
 		ranch_tcp, #{max_connections => 10, num_acceptors => 1},
-		notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
+		notify_and_wait_protocol, #{msg => connected, pid => self()}),
 	Port = ranch:get_port(Name),
 	ok = connect_loop(Port, 11, 150),
 	10 = ranch_server:count_connections(Name),
@@ -956,7 +956,7 @@ tcp_max_connections_infinity(_) ->
 	Name = name(),
 	{ok, _} = ranch:start_listener(Name,
 		ranch_tcp, #{max_connections => 10, num_acceptors => 1},
-		notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
+		notify_and_wait_protocol, #{msg => connected, pid => self()}),
 	Port = ranch:get_port(Name),
 	ok = connect_loop(Port, 20, 0),
 	10 = ranch_server:count_connections(Name),
@@ -989,7 +989,7 @@ tcp_set_max_connections(_) ->
 	Name = name(),
 	{ok, _} = ranch:start_listener(Name,
 		ranch_tcp, #{max_connections => 10, num_acceptors => 1},
-		notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
+		notify_and_wait_protocol, #{msg => connected, pid => self()}),
 	Port = ranch:get_port(Name),
 	ok = connect_loop(Port, 20, 0),
 	10 = ranch_server:count_connections(Name),
@@ -1011,7 +1011,7 @@ do_tcp_set_max_connections_clean(_) ->
 	Name = name(),
 	{ok, ListSupPid} = ranch:start_listener(Name,
 		ranch_tcp, #{max_connections => 4},
-		notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
+		notify_and_wait_protocol, #{msg => connected, pid => self()}),
 	Children = supervisor:which_children(ListSupPid),
 	{_, AccSupPid, _, _} = lists:keyfind(ranch_acceptors_sup, 1, Children),
 	1 = erlang:trace(ListSupPid, true, [procs]),
@@ -1069,11 +1069,11 @@ tcp_upgrade(_) ->
 	Name = name(),
 	{ok, _} = ranch:start_listener(Name,
 		ranch_tcp, #{},
-		notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
+		notify_and_wait_protocol, #{msg => connected, pid => self()}),
 	Port = ranch:get_port(Name),
 	ok = connect_loop(Port, 1, 0),
 	receive connected -> ok after 1000 -> error(timeout) end,
-	ranch:set_protocol_options(Name, [{msg, upgraded}, {pid, self()}]),
+	ranch:set_protocol_options(Name, #{msg => upgraded, pid => self()}),
 	ok = connect_loop(Port, 1, 0),
 	receive upgraded -> ok after 1000 -> error(timeout) end,
 	ok = ranch:stop_listener(Name).
@@ -1162,7 +1162,7 @@ do_supervisor_n_acceptors_m_conns_sups(NumAcceptors, NumConnsSups) ->
 	Name = name(),
 	{ok, Pid} = ranch:start_listener(Name,
 		ranch_tcp, #{num_conns_sups => NumConnsSups, num_acceptors => NumAcceptors},
-		notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
+		notify_and_wait_protocol, #{msg => connected, pid => self(), timeout => 10000}),
 	Port = ranch:get_port(Name),
 	ConnsSups = [ConnsSup || {_, ConnsSup} <- ranch_server:get_connections_sups(Name)],
 	NumConnsSups = length(ConnsSups),

+ 6 - 5
test/notify_and_wait_protocol.erl

@@ -2,12 +2,13 @@
 -behaviour(ranch_protocol).
 
 -export([start_link/3]).
--export([init/2]).
+-export([init/3]).
 
-start_link(_, _, [{msg, Msg}, {pid, TestPid}]) ->
-	Pid = spawn_link(?MODULE, init, [Msg, TestPid]),
+start_link(_, _, Opts = #{msg := Msg, pid := TestPid}) ->
+	Timeout = maps:get(timeout, Opts, 2500),
+	Pid = spawn_link(?MODULE, init, [Msg, TestPid, Timeout]),
 	{ok, Pid}.
 
-init(Msg, Pid) ->
+init(Msg, Pid, Timeout) ->
 	Pid ! Msg,
-	receive after 2500 -> ok end.
+	receive after Timeout -> ok end.