From 5eade4d1bc2f1189ef822e2bc622fe6aa6b5b582 Mon Sep 17 00:00:00 2001 From: William Yang Date: Wed, 11 Dec 2024 11:25:55 +0100 Subject: [PATCH] test(test): disable ct log in proper test --- test/example_client_connection.erl | 6 +++--- test/example_client_stream.erl | 18 +++++++++++++----- test/example_server_connection.erl | 3 ++- test/example_server_stream.erl | 11 ++++++----- test/prop_quic_types.hrl | 2 +- test/quicer_connection_SUITE.erl | 2 ++ test/quicer_ct.hrl | 22 ++++++++++++++++++++++ 7 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 test/quicer_ct.hrl diff --git a/test/example_client_connection.erl b/test/example_client_connection.erl index 01bf2bc9..cc83de5c 100644 --- a/test/example_client_connection.erl +++ b/test/example_client_connection.erl @@ -20,7 +20,7 @@ -include_lib("snabbkaffe/include/snabbkaffe.hrl"). -include("quicer_types.hrl"). - +-include("quicer_ct.hrl"). %% API -export([start_link/3]). @@ -83,7 +83,7 @@ new_conn(_Conn, #{version := _Vsn}, #{stream_opts := _SOpts} = S) -> connected(Conn, Flags, #{conn := Conn} = S) -> ?tp(debug, #{module => ?MODULE, conn => Conn, flags => Flags, event => connected}), - ct:pal("~p connected and expecting NST within 100ms", [?MODULE]), + ?LOG("~p connected and expecting NST within 100ms", [?MODULE]), {100, maps:merge(S, Flags)}. resumed(Conn, Data, #{resumed_callback := ResumeFun} = S) when @@ -116,7 +116,7 @@ new_stream( {ok, CBState#{streams := [{E, Stream} | Streams]}} end; Other -> - ct:pal("Start accepting remote stream error ~p", [Other]), + ?LOG("Start accepting remote stream error ~p", [Other]), {ok, CBState#{streams := [{start_error, Stream} | Streams]}} end. diff --git a/test/example_client_stream.erl b/test/example_client_stream.erl index 3323eb9e..8d28b650 100644 --- a/test/example_client_stream.erl +++ b/test/example_client_stream.erl @@ -37,6 +37,7 @@ -export([handle_stream_data/4]). -include("quicer.hrl"). +-include("quicer_ct.hrl"). -include_lib("snabbkaffe/include/snabbkaffe.hrl"). init_handoff(Stream, _StreamOpts, Conn, #{flags := Flags}) -> @@ -47,7 +48,7 @@ init_handoff(Stream, _StreamOpts, Conn, #{flags := Flags}) -> is_local => false, is_unidir => quicer:is_unidirectional(Flags) }, - ct:pal("init_handoff ~p", [{InitState, _StreamOpts}]), + ?LOG("init_handoff ~p", [{InitState, _StreamOpts}]), {ok, InitState}. post_handoff(Stream, _PostData, State) -> @@ -94,11 +95,11 @@ peer_send_shutdown(Stream, _Flags, S) -> send_complete(_Stream, false, S) -> {ok, S}; send_complete(_Stream, true = _IsCanceled, S) -> - ct:pal("~p : send is canceled", [?FUNCTION_NAME]), + ?LOG("~p : send is canceled", [?FUNCTION_NAME]), {ok, S}. send_shutdown_complete(_Stream, _Flags, S) -> - ct:pal("~p : stream send is complete", [?FUNCTION_NAME]), + ?LOG("~p : stream send is complete", [?FUNCTION_NAME]), {ok, S}. start_completed(Stream, #{status := success, stream_id := StreamId} = P, S) -> @@ -114,14 +115,21 @@ start_completed(_Stream, #{status := Other}, S) -> %% Local stream, Unidir handle_stream_data(Stream, Bin, _Flags, #{is_local := true, is_unidir := false} = State) -> ?tp(debug, #{stream => Stream, data => Bin, module => ?MODULE, dir => local_bidir}), - ct:pal("Client recv: ~p from ~p", [Bin, Stream]), + ?LOG("Client recv: ~p from ~p", [Bin, Stream]), {ok, State}; %% Remote stream handle_stream_data( Stream, Bin, _Flags, #{is_local := false, is_unidir := true, conn := _Conn} = State ) -> ?tp(debug, #{stream => Stream, data => Bin, module => ?MODULE, dir => remote_unidir}), - ct:pal("Client recv: ~p from ~p", [Bin, Stream]), + ?LOG("Client recv: ~p from ~p", [Bin, Stream]), + {ok, State}; +handle_stream_data( + Stream, Bin, _Flags, #{is_local := false, is_unidir := false, conn := _Conn} = State +) -> + %% for proper test + ?tp(debug, #{stream => Stream, data => Bin, module => ?MODULE, dir => remote_unidir}), + ?LOG("Client recv: ~p from ~p", [Bin, Stream]), {ok, State}; handle_stream_data( _Stream, diff --git a/test/example_server_connection.erl b/test/example_server_connection.erl index d63a338d..61c24be0 100644 --- a/test/example_server_connection.erl +++ b/test/example_server_connection.erl @@ -29,6 +29,7 @@ -include_lib("snabbkaffe/include/snabbkaffe.hrl"). -include("quicer_types.hrl"). +-include("quicer_ct.hrl"). %% Callback init -export([init/1]). @@ -149,7 +150,7 @@ dgram_recv(C, Bin, _Flag, S) -> case quicer:send_dgram(C, Bin) of {ok, _} -> ok; %% for testing when peer disable the receiving - Error -> ct:pal("send dgram error: ~p~n", [Error]) + Error -> ?LOG("send dgram error: ~p~n", [Error]) end, {ok, S}. diff --git a/test/example_server_stream.erl b/test/example_server_stream.erl index 11b5e6be..6a3549cf 100644 --- a/test/example_server_stream.erl +++ b/test/example_server_stream.erl @@ -39,6 +39,7 @@ -include("quicer.hrl"). -include_lib("snabbkaffe/include/snabbkaffe.hrl"). +-include("quicer_ct.hrl"). init_handoff(Stream, _StreamOpts, Conn, #{flags := Flags}) -> InitState = #{ @@ -48,7 +49,7 @@ init_handoff(Stream, _StreamOpts, Conn, #{flags := Flags}) -> is_local => false, is_unidir => quicer:is_unidirectional(Flags) }, - ct:pal("init_handoff ~p", [{InitState, _StreamOpts}]), + ?LOG("init_handoff ~p", [{InitState, _StreamOpts}]), {ok, InitState}. post_handoff(Stream, _PostData, State) -> @@ -99,11 +100,11 @@ peer_send_shutdown(Stream, _Flags, S) -> send_complete(_Stream, false, S) -> {ok, S}; send_complete(_Stream, true = _IsCanceled, S) -> - ct:pal("~p : send is canceled", [?FUNCTION_NAME]), + ?LOG("~p : send is canceled", [?FUNCTION_NAME]), {ok, S}. send_shutdown_complete(_Stream, _Flags, S) -> - ct:pal("~p : stream send is complete", [?FUNCTION_NAME]), + ?LOG("~p : stream send is complete", [?FUNCTION_NAME]), {ok, S}. start_completed(_Stream, #{status := success, stream_id := StreamId}, S) -> @@ -121,7 +122,7 @@ handle_stream_data( handle_stream_data(Stream, Bin, _Flags, #{is_unidir := false} = State) -> %% for bidir stream, we just echo in place. ?tp(debug, #{stream => Stream, data => Bin, module => ?MODULE, dir => bidir}), - ct:pal("Server recv: ~p from ~p", [Bin, Stream]), + ?LOG("Server recv: ~p from ~p", [Bin, Stream]), case quicer:send(Stream, Bin) of {ok, _} -> {ok, State}; @@ -132,7 +133,7 @@ handle_stream_data( Stream, Bin, _Flags, #{is_unidir := true, peer_stream := PeerStream, conn := Conn} = State ) -> ?tp(debug, #{stream => Stream, data => Bin, module => ?MODULE, dir => unidir}), - ct:pal("Server recv: ~p from ~p", [Bin, Stream]), + ?LOG("Server recv: ~p from ~p", [Bin, Stream]), case PeerStream of undefined -> diff --git a/test/prop_quic_types.hrl b/test/prop_quic_types.hrl index 149c29f3..744429f2 100644 --- a/test/prop_quic_types.hrl +++ b/test/prop_quic_types.hrl @@ -129,7 +129,7 @@ | {mtu_discovery_search_complete_timeout_us, uint64()} | {mtu_discovery_missing_probe_count, uint8()} | {max_binding_stateless_operations, uint16()} - | {stateless_operation_expiration_ms, 10..(1 bsl 16 -1)}. + | {stateless_operation_expiration_ms, 10..(1 bsl 16 - 1)}. -type quicer_conn_opts() :: [conn_opt()]. -type conn_opt() :: diff --git a/test/quicer_connection_SUITE.erl b/test/quicer_connection_SUITE.erl index edb74f39..8dfa9c80 100644 --- a/test/quicer_connection_SUITE.erl +++ b/test/quicer_connection_SUITE.erl @@ -549,6 +549,7 @@ tc_datagram_disallowed(Config) -> %% THEN: It get an error ?assertEqual({error, dgram_send_error, invalid_state}, quicer:send_dgram(Conn, <<"dg_ping">>)), quicer:shutdown_connection(Conn), + ok = quicer:terminate_listener(mqtt), ok. tc_datagram_peer_allowed(Config) -> @@ -585,6 +586,7 @@ tc_datagram_peer_allowed(Config) -> ok end, quicer:shutdown_connection(Conn), + ok = quicer:terminate_listener(mqtt), ok. tc_datagram_local_peer_allowed(Config) -> diff --git a/test/quicer_ct.hrl b/test/quicer_ct.hrl new file mode 100644 index 00000000..036c54e9 --- /dev/null +++ b/test/quicer_ct.hrl @@ -0,0 +1,22 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2024 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- +-ifndef(QUICER_CT_HRL). +-define(QUICER_CT_HRL, true). + +-define(LOG(_Arg1, _Arg2), logger:debug(_Arg1, _Arg2)). + +%% QUICER_CT_HRL +-endif.