From 1ba48c58b1462fb9d9d8c4d9a43878679aea8eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 3 Oct 2019 15:42:58 +0200 Subject: Make stream_error early_error reasons consistent Now both HTTP/1.1 and HTTP/2 follow the documented format. HTTP/1.1 was including an extra element containing the StreamID before, which was unnecessary because it is also given as argument to the callback. HTTP/2 early_error will now include headers in its PartialReq. --- test/metrics_SUITE.erl | 2 +- test/stream_handler_SUITE.erl | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/metrics_SUITE.erl b/test/metrics_SUITE.erl index d9ff7ea..971dd16 100644 --- a/test/metrics_SUITE.erl +++ b/test/metrics_SUITE.erl @@ -314,7 +314,7 @@ do_early_error(Config) -> ref := _, pid := From, streamid := 1, - reason := {stream_error, 1, protocol_error, _}, + reason := {stream_error, protocol_error, _}, partial_req := #{}, resp_status := 400, resp_headers := ExpectedRespHeaders, diff --git a/test/stream_handler_SUITE.erl b/test/stream_handler_SUITE.erl index 02aa437..130447d 100644 --- a/test/stream_handler_SUITE.erl +++ b/test/stream_handler_SUITE.erl @@ -248,6 +248,34 @@ do_crash_in_early_error_fatal(Config) -> %% Confirm the connection gets closed. gun_down(ConnPid). +early_error_stream_error_reason(Config) -> + doc("Confirm that the stream_error given to early_error/5 is consistent between protocols."), + Self = self(), + ConnPid = gun_open(Config), + %% We must use different solutions to hit early_error with a stream_error + %% reason in both protocols. + {Method, Headers, Status, Error} = case config(protocol, Config) of + http -> {<<"GET">>, [{<<"host">>, <<"host:port">>}], 400, protocol_error}; + http2 -> {<<"TRACE">>, [], 501, no_error} + end, + Ref = gun:request(ConnPid, Method, "/long_polling", [ + {<<"accept-encoding">>, <<"gzip">>}, + {<<"x-test-case">>, <<"early_error_stream_error_reason">>}, + {<<"x-test-pid">>, pid_to_list(Self)} + |Headers], <<>>), + %% Confirm init/3 is NOT called. The error occurs before we reach this step. + receive {Self, _, init, _, _, _} -> error(init) after 1000 -> ok end, + %% Confirm terminate/3 is NOT called. We have no state to give to it. + receive {Self, _, terminate, _, _, _} -> error(terminate) after 1000 -> ok end, + %% Confirm early_error/5 is called. + Reason = receive {Self, _, early_error, _, R, _, _, _} -> R after 1000 -> error(timeout) end, + %% Confirm that the Reason is a {stream_error, Reason, Human}. + {stream_error, Error, HumanReadable} = Reason, + true = is_atom(HumanReadable), + %% Receive a 400 or 501 error response. + {response, fin, Status, _} = gun:await(ConnPid, Ref), + ok. + set_options_ignore_unknown(Config) -> doc("Confirm that unknown options are ignored when using the set_options commands."), Self = self(), -- cgit v1.2.3