Skip to content

Commit

Permalink
fix: make prop tests stable
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Oct 21, 2024
1 parent fdc2350 commit c0815e2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
31 changes: 17 additions & 14 deletions test/example_client_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ new_stream(
} = CBState
) ->
%% Spawn new stream
case quicer_remote_stream:start_link(example_server_stream, Stream, Conn, SOpts, Flags) of
case quicer_remote_stream:start_link(example_client_stream, Stream, Conn, SOpts, Flags) of
{ok, StreamOwner} ->
case quicer:handoff_stream(Stream, StreamOwner) of
ok ->
Expand All @@ -116,7 +116,8 @@ new_stream(
{ok, CBState#{streams := [{E, Stream} | Streams]}}
end;
Other ->
Other
ct:pal("Start accepting remote stream error ~p", [Other]),
{ok, CBState#{streams := [{start_error, Stream} | Streams]}}
end.

dgram_state_changed(_Conn, _Flags, S) ->
Expand Down Expand Up @@ -152,17 +153,19 @@ peer_needs_streams(C, bidi_streams, S) ->
handle_info({'EXIT', _Pid, _Reason}, State) ->
{ok, State};
handle_info({quic, Sig, Stream, _} = Msg, #{streams := Streams} = S) when
%% @FIXME, not desired behavior.
%% Casued by inflight quic Msg during stream handoff
Sig == peer_send_shutdown orelse Sig == stream_closed
->
{OwnerPid, Stream} = lists:keyfind(Stream, 2, Streams),
NewS =
case OwnerPid == owner_down orelse OwnerPid == closed of
true ->
quicer:async_shutdown_stream(Stream),
S#{streams := lists:keydelete(Stream, 2, Streams)};
false ->
error(fixme)
end,
{ok, NewS}.
case lists:keyfind(Stream, 2, Streams) of
{Reason, Stream} when
Reason =:= owner_down orelse
Reason =:= closed orelse
Reason =:= start_error
->
_ = quicer:async_shutdown_stream(Stream),
{ok, S#{streams := lists:keydelete(Stream, 2, Streams)}};
{OwnerPid, Stream} when is_pid(OwnerPid) ->
{error, {fixme, bug_handoff_fail}};
false ->
%% garbage signals from already dead stream (such like crashed owner)
{ok, S}
end.
13 changes: 10 additions & 3 deletions test/example_client_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@
-include("quicer.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").

init_handoff(_Stream, _StreamOpts, _Conn, _Flags) ->
%% stream owner already set while starts.
{stop, not_impl, #{}}.
init_handoff(Stream, _StreamOpts, Conn, #{flags := Flags}) ->
InitState = #{
stream => Stream,
conn => Conn,
peer_stream => undefined,
is_local => false,
is_unidir => quicer:is_unidirectional(Flags)
},
ct:pal("init_handoff ~p", [{InitState, _StreamOpts}]),
{ok, InitState}.

post_handoff(Stream, _PostData, State) ->
ok = quicer:setopt(Stream, active, true),
Expand Down
2 changes: 1 addition & 1 deletion test/example_server_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,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}]),
ct:pal("init_handoff ~p", [{InitState, _StreamOpts}]),
{ok, InitState}.

post_handoff(Stream, _PostData, State) ->
Expand Down
2 changes: 2 additions & 0 deletions test/prop_stateful_server_conn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ next_state(State, Res, Call) ->

do_next_state(#{state := accepted} = State, {error, _}, {call, quicer, handshake, _Args}) ->
State;
do_next_state(#{state := _} = State, {error, closed}, {call, quicer, _, _Args}) ->
State#{state := closed};
do_next_state(#{state := accepted} = State, _Res, {call, quicer, handshake, _Args}) ->
State#{state := connected};
do_next_state(#{state := accepted} = State, _Res, {call, quicer, close_connection, _Args}) ->
Expand Down

0 comments on commit c0815e2

Please sign in to comment.