aboutsummaryrefslogtreecommitdiffstats
path: root/test/metrics_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/metrics_SUITE.erl')
-rw-r--r--test/metrics_SUITE.erl99
1 files changed, 76 insertions, 23 deletions
diff --git a/test/metrics_SUITE.erl b/test/metrics_SUITE.erl
index 74a259f..6a272f2 100644
--- a/test/metrics_SUITE.erl
+++ b/test/metrics_SUITE.erl
@@ -1,4 +1,4 @@
-%% Copyright (c) 2017, Loïc Hoguin <[email protected]>
+%% Copyright (c) 2017-2024, Loïc Hoguin <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -44,6 +44,8 @@ init_per_group(Name = h2, Config) ->
init_per_group(Name = h2c, Config) ->
Config1 = cowboy_test:init_http(Name, init_plain_opts(Config), Config),
lists:keyreplace(protocol, 1, Config1, {protocol, http2});
+init_per_group(Name = h3, Config) ->
+ cowboy_test:init_http3(Name, init_plain_opts(Config), Config);
init_per_group(Name = http_compress, Config) ->
cowboy_test:init_http(Name, init_compress_opts(Config), Config);
init_per_group(Name = https_compress, Config) ->
@@ -52,10 +54,12 @@ init_per_group(Name = h2_compress, Config) ->
cowboy_test:init_http2(Name, init_compress_opts(Config), Config);
init_per_group(Name = h2c_compress, Config) ->
Config1 = cowboy_test:init_http(Name, init_compress_opts(Config), Config),
- lists:keyreplace(protocol, 1, Config1, {protocol, http2}).
+ lists:keyreplace(protocol, 1, Config1, {protocol, http2});
+init_per_group(Name = h3_compress, Config) ->
+ cowboy_test:init_http3(Name, init_compress_opts(Config), Config).
end_per_group(Name, _) ->
- cowboy:stop_listener(Name).
+ cowboy_test:stop_group(Name).
init_plain_opts(Config) ->
#{
@@ -157,16 +161,24 @@ do_get(Path, UserData, Config) ->
#{
ref := _,
pid := From,
- streamid := 1,
- reason := normal,
+ streamid := StreamID,
+ reason := normal, %% @todo Getting h3_no_error here.
req := #{},
informational := [],
user_data := UserData
} = Metrics,
+ do_check_streamid(StreamID, Config),
%% All good!
gun:close(ConnPid)
end.
+do_check_streamid(StreamID, Config) ->
+ case config(protocol, Config) of
+ http -> 1 = StreamID;
+ http2 -> 1 = StreamID;
+ http3 -> 0 = StreamID
+ end.
+
post_body(Config) ->
doc("Confirm metrics are correct for a normal POST request."),
%% Perform a POST request.
@@ -218,12 +230,13 @@ post_body(Config) ->
#{
ref := _,
pid := From,
- streamid := 1,
+ streamid := StreamID,
reason := normal,
req := #{},
informational := [],
user_data := #{}
} = Metrics,
+ do_check_streamid(StreamID, Config),
%% All good!
gun:close(ConnPid)
end.
@@ -273,12 +286,13 @@ no_resp_body(Config) ->
#{
ref := _,
pid := From,
- streamid := 1,
+ streamid := StreamID,
reason := normal,
req := #{},
informational := [],
user_data := #{}
} = Metrics,
+ do_check_streamid(StreamID, Config),
%% All good!
gun:close(ConnPid)
end.
@@ -291,7 +305,8 @@ early_error(Config) ->
%% 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}
+ http2 -> {<<"TRACE">>, [], 501, no_error};
+ http3 -> {<<"TRACE">>, [], 501, h3_no_error}
end,
Ref = gun:request(ConnPid, Method, "/", [
{<<"accept-encoding">>, <<"gzip">>},
@@ -305,7 +320,7 @@ early_error(Config) ->
#{
ref := _,
pid := From,
- streamid := 1,
+ streamid := StreamID,
reason := {stream_error, Error, _},
partial_req := #{},
resp_status := Status,
@@ -313,6 +328,7 @@ early_error(Config) ->
early_error_time := _,
resp_body_length := 0
} = Metrics,
+ do_check_streamid(StreamID, Config),
ExpectedRespHeaders = maps:from_list(RespHeaders),
%% All good!
gun:close(ConnPid)
@@ -321,7 +337,8 @@ early_error(Config) ->
early_error_request_line(Config) ->
case config(protocol, Config) of
http -> do_early_error_request_line(Config);
- http2 -> doc("There are no request lines in HTTP/2.")
+ http2 -> doc("There are no request lines in HTTP/2.");
+ http3 -> doc("There are no request lines in HTTP/3.")
end.
do_early_error_request_line(Config) ->
@@ -341,7 +358,7 @@ do_early_error_request_line(Config) ->
#{
ref := _,
pid := From,
- streamid := 1,
+ streamid := StreamID,
reason := {connection_error, protocol_error, _},
partial_req := #{},
resp_status := 400,
@@ -349,6 +366,7 @@ do_early_error_request_line(Config) ->
early_error_time := _,
resp_body_length := 0
} = Metrics,
+ do_check_streamid(StreamID, Config),
ExpectedRespHeaders = maps:from_list(RespHeaders),
%% All good!
ok
@@ -362,7 +380,9 @@ stream_reply(Config) ->
ws(Config) ->
case config(protocol, Config) of
http -> do_ws(Config);
- http2 -> doc("It is not currently possible to switch to Websocket over HTTP/2.")
+ %% @todo The test can be implemented for HTTP/2.
+ http2 -> doc("It is not currently possible to switch to Websocket over HTTP/2.");
+ http3 -> {skip, "Gun does not currently support Websocket over HTTP/3."}
end.
do_ws(Config) ->
@@ -405,7 +425,7 @@ do_ws(Config) ->
#{
ref := _,
pid := From,
- streamid := 1,
+ streamid := StreamID,
reason := switch_protocol,
req := #{},
%% A 101 upgrade response was sent.
@@ -420,6 +440,7 @@ do_ws(Config) ->
}],
user_data := #{}
} = Metrics,
+ do_check_streamid(StreamID, Config),
%% All good!
ok
end,
@@ -438,7 +459,15 @@ error_response(Config) ->
{<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())}
]),
- {response, fin, 500, RespHeaders} = gun:await(ConnPid, Ref, infinity),
+ Protocol = config(protocol, Config),
+ RespHeaders = case gun:await(ConnPid, Ref, infinity) of
+ {response, fin, 500, RespHeaders0} ->
+ RespHeaders0;
+ %% The RST_STREAM arrived before the start of the response.
+ %% See maybe_h3_error comment for details.
+ {error, {stream_error, {stream_error, h3_internal_error, _}}} when Protocol =:= http3 ->
+ unknown
+ end,
timer:sleep(100),
%% Receive the metrics and validate them.
receive
@@ -463,25 +492,33 @@ error_response(Config) ->
resp_headers := ExpectedRespHeaders,
resp_body_length := 0
} = Metrics,
- ExpectedRespHeaders = maps:from_list(RespHeaders),
+ case RespHeaders of
+ %% The HTTP/3 stream has reset too early so we can't
+ %% verify the response headers.
+ unknown ->
+ ok;
+ _ ->
+ ExpectedRespHeaders = maps:from_list(RespHeaders)
+ end,
%% The request process executed normally.
#{procs := Procs} = Metrics,
[{_, #{
spawn := ProcSpawn,
exit := ProcExit,
- reason := {crash, _StackTrace}
+ reason := {crash, StackTrace}
}}] = maps:to_list(Procs),
true = ProcSpawn =< ProcExit,
%% Confirm other metadata are as expected.
#{
ref := _,
pid := From,
- streamid := 1,
- reason := {internal_error, {'EXIT', _Pid, {crash, _StackTrace}}, 'Stream process crashed.'},
+ streamid := StreamID,
+ reason := {internal_error, {'EXIT', _Pid, {crash, StackTrace}}, 'Stream process crashed.'},
req := #{},
informational := [],
user_data := #{}
} = Metrics,
+ do_check_streamid(StreamID, Config),
%% All good!
gun:close(ConnPid)
end.
@@ -495,7 +532,15 @@ error_response_after_reply(Config) ->
{<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())}
]),
- {response, fin, 200, RespHeaders} = gun:await(ConnPid, Ref, infinity),
+ Protocol = config(protocol, Config),
+ RespHeaders = case gun:await(ConnPid, Ref, infinity) of
+ {response, fin, 200, RespHeaders0} ->
+ RespHeaders0;
+ %% The RST_STREAM arrived before the start of the response.
+ %% See maybe_h3_error comment for details.
+ {error, {stream_error, {stream_error, h3_internal_error, _}}} when Protocol =:= http3 ->
+ unknown
+ end,
timer:sleep(100),
%% Receive the metrics and validate them.
receive
@@ -520,25 +565,33 @@ error_response_after_reply(Config) ->
resp_headers := ExpectedRespHeaders,
resp_body_length := 0
} = Metrics,
- ExpectedRespHeaders = maps:from_list(RespHeaders),
+ case RespHeaders of
+ %% The HTTP/3 stream has reset too early so we can't
+ %% verify the response headers.
+ unknown ->
+ ok;
+ _ ->
+ ExpectedRespHeaders = maps:from_list(RespHeaders)
+ end,
%% The request process executed normally.
#{procs := Procs} = Metrics,
[{_, #{
spawn := ProcSpawn,
exit := ProcExit,
- reason := {crash, _StackTrace}
+ reason := {crash, StackTrace}
}}] = maps:to_list(Procs),
true = ProcSpawn =< ProcExit,
%% Confirm other metadata are as expected.
#{
ref := _,
pid := From,
- streamid := 1,
- reason := {internal_error, {'EXIT', _Pid, {crash, _StackTrace}}, 'Stream process crashed.'},
+ streamid := StreamID,
+ reason := {internal_error, {'EXIT', _Pid, {crash, StackTrace}}, 'Stream process crashed.'},
req := #{},
informational := [],
user_data := #{}
} = Metrics,
+ do_check_streamid(StreamID, Config),
%% All good!
gun:close(ConnPid)
end.