Skip to content

Commit

Permalink
Merge pull request #267 from qzhuyan/test/proper-stateful-server-conn
Browse files Browse the repository at this point in the history
Test/proper stateful server conn
  • Loading branch information
qzhuyan authored Feb 29, 2024
2 parents 5f1068f + cdc67d8 commit dc3e24c
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-c-lcov
files: coverage/proper-lcov.info coverage/lcov.info
parallel: true
git-branch: ${{ github.ref_name }}
git-commit: ${{ github.sha }}
Expand All @@ -53,6 +54,7 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-c-lcov-feature
files: coverage/proper-lcov.info coverage/lcov.info
parallel: true
git-branch: ${{ github.ref_name }}
git-commit: ${{ github.sha }}
Expand Down
4 changes: 2 additions & 2 deletions src/quicer_listener_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ listener(Name) when is_atom(Name) ->
init([]) ->
SupFlags = #{
strategy => one_for_one,
intensity => 60,
period => 30
intensity => 10000,
period => 1
},
{ok, {SupFlags, []}}.

Expand Down
5 changes: 3 additions & 2 deletions test/example_client_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ init(ConnOpts) when is_list(ConnOpts) ->
init(#{stream_opts := SOpts} = S) when is_list(SOpts) ->
init(S#{stream_opts := maps:from_list(SOpts)});
init(#{conn := Conn, stream_opts := SOpts} = ConnOpts) when is_map(ConnOpts) ->
process_flag(trap_exit, true),
%% for accepting
{ok, Stream2} = quicer_remote_stream:start(example_client_stream, Conn, SOpts, [
{spawn_opt, [link]}
Expand All @@ -69,7 +70,7 @@ init(#{conn := Conn, stream_opts := SOpts} = ConnOpts) when is_map(ConnOpts) ->
{ok, _} = quicer_stream:send(
Stream1, <<"ping_from_example">>, ?QUICER_SEND_FLAG_SYNC bor ?QUIC_SEND_FLAG_FIN
),
{ok, ConnOpts#{master_stream_pair => {Stream1, Stream2}}}.
{ok, ConnOpts#{streams => [], master_stream_pair => {Stream1, Stream2}}}.

closed(_Conn, #{is_peer_acked := true}, S) ->
{stop, normal, S};
Expand Down Expand Up @@ -107,7 +108,7 @@ new_stream(
%% Spawn new stream
case quicer_remote_stream:start_link(example_server_stream, Stream, Conn, SOpts, Flags) of
{ok, StreamOwner} ->
quicer_connection:handoff_stream(Stream, StreamOwner),
quicer:handoff_stream(Stream, StreamOwner),
{ok, CBState#{streams := [{StreamOwner, Stream} | Streams]}};
Other ->
Other
Expand Down
21 changes: 20 additions & 1 deletion test/example_client_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ peer_send_aborted(Stream, ErrorCode, #{is_unidir := true, is_local := false} = S
{ok, S}.

peer_send_shutdown(Stream, _Flags, S) ->
ok = quicer:async_shutdown_stream(Stream, ?QUIC_STREAM_SHUTDOWN_FLAG_GRACEFUL, 0),
case quicer:async_shutdown_stream(Stream, ?QUIC_STREAM_SHUTDOWN_FLAG_GRACEFUL, 0) of
ok ->
ok;
{error, closed} ->
ok
end,
{ok, S}.

send_complete(_Stream, false, S) ->
Expand Down Expand Up @@ -110,6 +115,20 @@ handle_stream_data(
) ->
?tp(debug, #{stream => Stream, data => Bin, module => ?MODULE, dir => remote_unidir}),
ct:pal("Client recv: ~p from ~p", [Bin, Stream]),
{ok, State};
handle_stream_data(
_Stream,
_,
#{
absolute_offset :=
0
},
#{
is_local := false,
is_unidir := false
} = State
) ->
%% for proper test
{ok, State}.

passive(Stream, undefined, S) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(prop_stateful_conn).
-module(prop_stateful_client_conn).
-compile([export_all]).
-include_lib("proper/include/proper.hrl").
-include_lib("quicer/include/quicer_types.hrl").
Expand Down Expand Up @@ -168,6 +168,10 @@ postcondition(
{error, timeout}
) when Me =/= Owner orelse State == closed ->
true;
postcondition(
#{state := closed}, {call, quicer, negotiated_protocol, [_]}, {error, invalid_parameter}
) ->
true;
postcondition(_State, {call, quicer, negotiated_protocol, [_]}, {ok, <<"prop">>}) ->
true;
postcondition(_State, {call, quicer, peername, [_]}, {ok, {_, 14568}}) ->
Expand Down
Loading

0 comments on commit dc3e24c

Please sign in to comment.