From 839397545966a287592b1700aab379b46cf3f47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 5 Jun 2025 15:38:28 +0200 Subject: [PATCH] Confirm handler terminates with AppCode/AppMsg --- test/draft_h3_webtransport_SUITE.erl | 26 ++++++++++++++++++++++++++ test/handlers/wt_echo_h.erl | 8 +++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/test/draft_h3_webtransport_SUITE.erl b/test/draft_h3_webtransport_SUITE.erl index 2f1a1631..b271f590 100644 --- a/test/draft_h3_webtransport_SUITE.erl +++ b/test/draft_h3_webtransport_SUITE.erl @@ -482,6 +482,32 @@ close_wt_session_server(Config) -> %% Application Error Message: A UTF-8 encoded error message string provided by the application closing the session. The message takes up the remainder of the capsule, and its length MUST NOT exceed 1024 bytes. (6) %% @todo close_wt_session_app_code_msg_client +close_wt_session_app_code_msg_client(Config) -> + doc("The WT client can close a single session with an application error code " + "and an application error message. (draft_webtrans_http3 4.6)"), + %% Connect to the WebTransport server. + #{ + conn := Conn, + connect_stream_ref := ConnectStreamRef, + session_id := SessionID + } = do_webtransport_connect(Config), + %% Create a bidi stream, send a special instruction to make it propagate events. + {ok, LocalStreamRef} = quicer:start_stream(Conn, #{}), + EventPidBin = term_to_binary(self()), + {ok, _} = quicer:send(LocalStreamRef, <<1:2, 16#41:14, 0:2, SessionID:6, + "TEST:event_pid:", EventPidBin/binary>>), + %% Send the CLOSE_WEBTRANSPORT_SESSION capsule on the CONNECT stream. + {ok, _} = quicer:send(ConnectStreamRef, + cow_capsule:close_wt_session(17, <<"seventeen">>), + ?QUIC_SEND_FLAG_FIN), + %% @todo Stop reading from the CONNECt stream too. (STOP_SENDING) + %% Receive the terminate event from the WT handler. + receive + {'$wt_echo_h', terminate, {closed, 17, <<"seventeen">>}, _, _} -> + ok + after 1000 -> + error({timeout, waiting_for_terminate_event}) + end. close_wt_session_app_code_server(Config) -> doc("The WT server can close a single session with an application error code. " diff --git a/test/handlers/wt_echo_h.erl b/test/handlers/wt_echo_h.erl index 7bb786be..bb68e392 100644 --- a/test/handlers/wt_echo_h.erl +++ b/test/handlers/wt_echo_h.erl @@ -57,7 +57,9 @@ webtransport_handle(Event = {stream_data, _StreamID, _IsFin, <<"TEST:", Test/bit <<"close_app_code">> -> {[{close, 1234567890}], Streams}; <<"close_app_code_msg">> -> - {[{close, 1234567890, <<"onetwothreefourfivesixseveneightnineten">>}], Streams} + {[{close, 1234567890, <<"onetwothreefourfivesixseveneightnineten">>}], Streams}; + <<"event_pid:", EventPidBin/bits>> -> + {[], Streams#{event_pid => binary_to_term(EventPidBin)}} end; webtransport_handle(Event = {stream_data, StreamID, IsFin, Data}, Streams) -> ct:pal("WT handle ~p~n", [Event]), @@ -85,6 +87,10 @@ webtransport_info({try_again, Event}, Streams) -> ct:pal("try_again ~p", [Event]), webtransport_handle(Event, Streams). +terminate(Reason, Req, State=#{event_pid := EventPid}) -> + ct:pal("terminate ~p ~p ~p", [Reason, Req, State]), + EventPid ! {'$wt_echo_h', terminate, Reason, Req, State}, + ok; terminate(Reason, Req, State) -> ct:pal("terminate ~p ~p ~p", [Reason, Req, State]), ok.