Skip to content

Commit c328380

Browse files
committed
test(proper): cover the case when the stream owner is dead after accepted
1 parent 8464851 commit c328380

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

c_src/quicer_tp.c

-1
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,4 @@ tp_snk(ErlNifEnv *env,
8484
enif_make_tuple2(env, ATOM_IN_ENV(TRACE), snk_event));
8585
enif_send(NULL, pid, env, report);
8686
enif_free_env(env);
87-
8887
}

test/example_client_connection.erl

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ handle_info({quic, Sig, Stream, _} = Msg, #{streams := Streams} = S) when
164164
_ = quicer:async_shutdown_stream(Stream),
165165
{ok, S#{streams := lists:keydelete(Stream, 2, Streams)}};
166166
{OwnerPid, Stream} when is_pid(OwnerPid) ->
167+
%%% you should not hit here in testing, if so, fire one issue report
167168
{error, {fixme, bug_handoff_fail}};
168169
false ->
169170
%% garbage signals from already dead stream (such like crashed owner)

test/prop_stateful_client_conn.erl

+28
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
postcondition/3
2929
]).
3030

31+
%% Helpers
32+
-export([
33+
spawn_stream_acceptor/3
34+
]).
3135
%%%%%%%%%%%%%%%%%%
3236
%%% PROPERTIES %%%
3337
%%%%%%%%%%%%%%%%%%
@@ -72,6 +76,10 @@ command(#{handle := Handle}) ->
7276
{100, {call, quicer, getopt, [Handle, ?LET({Opt, _}, conn_opt(), Opt)]}},
7377
{100,
7478
{call, quicer, async_accept_stream, [Handle, ?LET(Opts, quicer_acceptor_opts(), Opts)]}},
79+
{100,
80+
{call, ?MODULE, spawn_stream_acceptor, [
81+
Handle, ?LET(Opts, quicer_acceptor_opts(), Opts), range(0, 200)
82+
]}},
7583
{100, {call, quicer, peername, [Handle]}},
7684
{50, {call, quicer, peercert, [Handle]}},
7785
{10, {call, quicer, negotiated_protocol, [Handle]}},
@@ -205,6 +213,8 @@ postcondition(#{handle := _H, state := closed}, {call, quicer, get_connections,
205213
true;
206214
postcondition(#{state := closed}, {call, _Mod, _Fun, _Args}, {error, closed}) ->
207215
true;
216+
postcondition(_State, {call, ?MODULE, spawn_stream_acceptor, _Args}, ok) ->
217+
true;
208218
postcondition(_State, {call, _Mod, _Fun, _Args} = _Call, _Res) ->
209219
false.
210220

@@ -278,3 +288,21 @@ default_conn_opts() ->
278288
{certfile, "./msquic/submodules/openssl/test/certs/servercert.pem"},
279289
{keyfile, "./msquic/submodules/openssl/test/certs/serverkey.pem"}
280290
].
291+
292+
%% Test helpers
293+
spawn_stream_acceptor(ConnHandle, Opts, DieAfter) ->
294+
spawn(
295+
fun() ->
296+
do_accept_stream(ConnHandle, Opts, DieAfter)
297+
end
298+
),
299+
ok.
300+
301+
do_accept_stream(Conn, Opts, DieAfter) ->
302+
{ok, Conn} = quicer:async_accept_stream(Conn, Opts),
303+
receive
304+
{quicer, new_stream, _Stream, _Flags} ->
305+
timer:sleep(DieAfter)
306+
after DieAfter ->
307+
ok
308+
end.

test/prop_stateful_server_conn.erl

+14-6
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ postcondition(#{state := accepted}, {call, quicer, handshake, _Args}, {ok, _}) -
139139
true;
140140
postcondition(#{state := accepted}, {call, quicer, handshake, _Args}, {error, invalid_state}) ->
141141
true;
142-
postcondition(#{state := accepted}, {call, quicer, handshake, _Args}, {error, timeout}) ->
142+
postcondition(#{state := closed}, {call, quicer, handshake, _}, {error, timeout}) ->
143+
true;
144+
postcondition(#{state := _}, {call, quicer, handshake, _Args}, {error, timeout}) ->
143145
%% @FIXME
144146
true;
145147
postcondition(
@@ -209,21 +211,23 @@ postcondition(_State, {call, quicer, close_connection, _Args}, ok) ->
209211
true;
210212
postcondition(_State, {call, quicer, shutdown_connection, _Args}, ok) ->
211213
true;
212-
postcondition(accepted, {call, quicer, close_connection, _Args}, {error, timeout}) ->
214+
postcondition(#{state := accepted}, {call, quicer, close_connection, _Args}, {error, timeout}) ->
215+
true;
216+
postcondition(#{state := accepted}, {call, quicer, shutdown_connection, _Args}, {error, timeout}) ->
213217
true;
214-
postcondition(accepted, {call, quicer, shutdown_connection, _Args}, {error, timeout}) ->
218+
postcondition(#{state := accepted}, {call, quicer, close_connection, _Args}, {error, closed}) ->
215219
true;
216-
postcondition(accepted, {call, quicer, close_connection, _Args}, {error, closed}) ->
220+
postcondition(#{state := closed}, {call, quicer, close_connection, _Args}, {error, timeout}) ->
217221
true;
218222
postcondition(_, {call, quicer, shutdown_connection, [_, _, Tout]}, {error, timeout}) when
219223
Tout < 200
220224
->
221225
true;
222-
postcondition(_, {call, quicer, close_connection, [_, _, Tout]}, {error, timeout}) when
226+
postcondition(_, {call, quicer, close_connection, [_, Tout]}, {error, timeout}) when
223227
Tout < 200
224228
->
225229
true;
226-
postcondition(accepted, {call, quicer, shutdown_connection, _Args}, {error, closed}) ->
230+
postcondition(#{state := accepted}, {call, quicer, shutdown_connection, _Args}, {error, closed}) ->
227231
true;
228232
postcondition(
229233
#{me := Me, owner := Owner, state := State},
@@ -243,6 +247,10 @@ postcondition(
243247
S =:= accepted orelse S =:= closed
244248
->
245249
true;
250+
postcondition(
251+
#{state := accepted}, {call, quicer, async_csend, [_]}, {error, stm_send_error, aborted}
252+
) ->
253+
true;
246254
postcondition(#{state := accepted}, {call, quicer, async_csend, [_]}, {error, timeout}) ->
247255
%% @FIXME https://github.com/emqx/quic/issues/265
248256
true;

tools/run/bin/lib.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ do_run() {
2929
done
3030
;;
3131
proper)
32-
escript "$REBAR3" as test proper
32+
escript "$REBAR3" as test proper --noshrink
3333
;;
3434
*)
3535
escript "$REBAR3" $@

0 commit comments

Comments
 (0)