From 87e2184d6953882881f93b42541b8c08331d9892 Mon Sep 17 00:00:00 2001 From: William Yang Date: Tue, 5 Sep 2023 15:08:43 +0200 Subject: [PATCH] test: add a start listener sync MsQuic 2.2 looks slow to start listener --- test/quicer_listener_SUITE.erl | 22 +++++++++++++--------- test/quicer_snb_SUITE.erl | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/test/quicer_listener_SUITE.erl b/test/quicer_listener_SUITE.erl index 716974e4..951525e8 100644 --- a/test/quicer_listener_SUITE.erl +++ b/test/quicer_listener_SUITE.erl @@ -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. @@ -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. @@ -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) -> @@ -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: diff --git a/test/quicer_snb_SUITE.erl b/test/quicer_snb_SUITE.erl index a7fd46a4..f6e3fcea 100644 --- a/test/quicer_snb_SUITE.erl +++ b/test/quicer_snb_SUITE.erl @@ -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, []]) @@ -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),