Skip to content

Commit

Permalink
test(test): disable ct log in proper test
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Dec 11, 2024
1 parent 2ad3d03 commit 5eade4d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
6 changes: 3 additions & 3 deletions test/example_client_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-include("quicer_types.hrl").

-include("quicer_ct.hrl").
%% API
-export([start_link/3]).

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
18 changes: 13 additions & 5 deletions test/example_client_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}) ->
Expand All @@ -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) ->
Expand Down Expand Up @@ -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) ->
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/example_server_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-include("quicer_types.hrl").
-include("quicer_ct.hrl").

%% Callback init
-export([init/1]).
Expand Down Expand Up @@ -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}.

Expand Down
11 changes: 6 additions & 5 deletions test/example_server_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = #{
Expand All @@ -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) ->
Expand Down Expand Up @@ -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) ->
Expand All @@ -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};
Expand All @@ -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 ->
Expand Down
2 changes: 1 addition & 1 deletion test/prop_quic_types.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -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() ::
Expand Down
2 changes: 2 additions & 0 deletions test/quicer_connection_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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) ->
Expand Down
22 changes: 22 additions & 0 deletions test/quicer_ct.hrl
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 5eade4d

Please sign in to comment.