Skip to content

Commit

Permalink
test: add a start listener sync
Browse files Browse the repository at this point in the history
MsQuic 2.2 looks slow to start listener
  • Loading branch information
qzhuyan committed Sep 9, 2023
1 parent 5b18403 commit 87e2184
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/quicer_listener_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ tc_open_listener(Config) ->
{ok, {_, Port}} = quicer:sockname(L),
{error, eaddrinuse} = gen_udp:open(Port),
ok = quicer:close_listener(L),
{ok, P} = snabbkaffe:retry(100, 10, fun()-> gen_udp:open(Port) end),
{ok, P} = snabbkaffe:retry(100, 10, fun()-> {ok, _} = gen_udp:open(Port) end),
ok = gen_udp:close(P),
ok.

Expand Down Expand Up @@ -251,22 +251,24 @@ tc_open_listener_with_wrong_cert_password(Config) ->
, quicer:listen(Port, default_listen_opts(PasswordCerts ++ Config))).

tc_open_listener_bind(Config) ->
ListenOn = "127.0.0.1:4567",
Port = select_port(),
ListenOn = "127.0.0.1"++":"++integer_to_list(Port),
{ok, L} = quicer:listen(ListenOn, default_listen_opts(Config)),
{ok, {_, _}} = quicer:sockname(L),
{error, eaddrinuse} = gen_udp:open(4567),
{error, eaddrinuse} = gen_udp:open(Port),
ok = quicer:close_listener(L),
{ok, P} = snabbkaffe:retry(100, 10, fun() -> gen_udp:open(4567) end),
{ok, P} = snabbkaffe:retry(100, 10, fun() -> {ok, _} = gen_udp:open(Port) end),
ok = gen_udp:close(P),
ok.

tc_open_listener_bind_v6(Config) ->
ListenOn = "[::1]:4567",
Port = select_port(),
ListenOn = "[::1]"++":"++integer_to_list(Port),
{ok, L} = quicer:listen(ListenOn, default_listen_opts(Config)),
{ok, {_, _}} = quicer:sockname(L),
{error, eaddrinuse} = gen_udp:open(4567, [{ip, {0, 0, 0, 0, 0, 0, 0, 1}}]),
{error, eaddrinuse} = gen_udp:open(Port, [{ip, {0, 0, 0, 0, 0, 0, 0, 1}}]),
ok = quicer:close_listener(L),
{ok, P} = snabbkaffe:retry(100, 10, fun() -> gen_udp:open(4567, [{ip, {0, 0, 0, 0, 0, 0, 0, 1}}]) end),
{ok, P} = snabbkaffe:retry(100, 10, fun() -> {ok, _} = gen_udp:open(Port, [{ip, {0, 0, 0, 0, 0, 0, 0, 1}}]) end),
ok = gen_udp:close(P),
ok.

Expand Down Expand Up @@ -325,7 +327,7 @@ tc_stop_start_listener(Config) ->
LConf = default_listen_opts(Config),
{ok, L} = quicer:listen(Port, LConf),
ok = quicer:stop_listener(L),
ok = snabbkaffe:retry(100, 10, fun() -> quicer:start_listener(L, Port, LConf) end),
ok = snabbkaffe:retry(100, 10, fun() -> ok = quicer:start_listener(L, Port, LConf) end),
ok = quicer:close_listener(L).

tc_stop_close_listener(Config) ->
Expand Down Expand Up @@ -465,7 +467,9 @@ tc_listener_stopped_when_owner_die(Config) ->
ok = quicer:close_listener(L1).

select_port() ->
select_free_port(quic).
Port = select_free_port(quic),
timer:sleep(100),
Port.

%%%_* Emacs ====================================================================
%%% Local Variables:
Expand Down
3 changes: 3 additions & 0 deletions test/quicer_snb_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1701,8 +1701,10 @@ tc_conn_stop_notify_acceptor(Config) ->
ct:pal("Listener Options: ~p", [Options]),
?check_trace(#{timetrap => 10000},
begin
Parent = self(),
{SPid, Ref} = spawn_monitor(fun() ->
{ok, Listener} = quicer:listen(Port, ListenerOpts),
Parent ! {self(), ready},
{ok, Conn} = quicer:accept(Listener, []),
Acceptors = lists:map(fun(_) ->
spawn(quicer, accept_stream, [Conn, []])
Expand All @@ -1714,6 +1716,7 @@ tc_conn_stop_notify_acceptor(Config) ->
end,
exit({normal, Acceptors})
end),
receive {SPid, ready} -> ok end,
{ok, Conn} = quicer:connect("localhost", Port, default_conn_opts(), infinity),
quicer:shutdown_connection(Conn),

Expand Down

0 comments on commit 87e2184

Please sign in to comment.