aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-21 13:12:36 +0100
committerLoïc Hoguin <[email protected]>2017-10-21 13:12:36 +0100
commit2a905e9bda3df9260602fb68e9415a3ad4e0cecb (patch)
treee183293ea515d2d340b84c458324fad710c67601
parentc62ce1c63e2801640e36c7a480e9250ec8108d24 (diff)
downloadcowboy-2a905e9bda3df9260602fb68e9415a3ad4e0cecb.tar.gz
cowboy-2a905e9bda3df9260602fb68e9415a3ad4e0cecb.tar.bz2
cowboy-2a905e9bda3df9260602fb68e9415a3ad4e0cecb.zip
Add a metrics test when the handler didn't send anything
Also fix a test group to use h2 instead of HTTP/1.1.
-rw-r--r--test/handlers/default_h.erl8
-rw-r--r--test/metrics_SUITE.erl61
2 files changed, 67 insertions, 2 deletions
diff --git a/test/handlers/default_h.erl b/test/handlers/default_h.erl
new file mode 100644
index 0000000..b89c31b
--- /dev/null
+++ b/test/handlers/default_h.erl
@@ -0,0 +1,8 @@
+%% This module does not do anything.
+
+-module(default_h).
+
+-export([init/2]).
+
+init(Req, Opts) ->
+ {ok, Req, Opts}.
diff --git a/test/metrics_SUITE.erl b/test/metrics_SUITE.erl
index 90ffc9b..b43e475 100644
--- a/test/metrics_SUITE.erl
+++ b/test/metrics_SUITE.erl
@@ -33,7 +33,7 @@ init_per_group(Name = http, Config) ->
init_per_group(Name = https, Config) ->
cowboy_test:init_http(Name, init_plain_opts(Config), Config);
init_per_group(Name = h2, Config) ->
- cowboy_test:init_http(Name, init_plain_opts(Config), Config);
+ cowboy_test:init_http2(Name, init_plain_opts(Config), 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});
@@ -42,7 +42,7 @@ init_per_group(Name = http_compress, Config) ->
init_per_group(Name = https_compress, Config) ->
cowboy_test:init_http(Name, init_compress_opts(Config), Config);
init_per_group(Name = h2_compress, Config) ->
- cowboy_test:init_http(Name, init_compress_opts(Config), 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}).
@@ -67,6 +67,7 @@ init_compress_opts(Config) ->
init_routes(_) -> [
{"localhost", [
{"/", hello_h, []},
+ {"/default", default_h, []},
{"/full/:key", echo_h, []}
]}
].
@@ -200,3 +201,59 @@ post_body(Config) ->
after 1000 ->
error(timeout)
end.
+
+no_resp_body(Config) ->
+ doc("Confirm metrics are correct for a 204 response to a GET request."),
+ %% Perform a GET request.
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, "/default", [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"x-test-pid">>, pid_to_list(self())}
+ ]),
+ {response, fin, 204, RespHeaders} = gun:await(ConnPid, Ref),
+ gun:close(ConnPid),
+ %% Receive the metrics and validate them.
+ receive
+ {metrics, From, Metrics} ->
+ %% Ensure the timestamps are in the expected order.
+ #{
+ req_start := ReqStart, req_end := ReqEnd,
+ resp_start := RespStart, resp_end := RespEnd
+ } = Metrics,
+ true = (ReqStart =< RespStart)
+ and (RespStart =< RespEnd)
+ and (RespEnd =< ReqEnd),
+ %% We didn't send a body.
+ #{
+ req_body_start := undefined,
+ req_body_end := undefined,
+ req_body_length := 0
+ } = Metrics,
+ %% We got a 200 response with a body.
+ #{
+ resp_status := 204,
+ resp_headers := ExpectedRespHeaders,
+ resp_body_length := 0
+ } = Metrics,
+ ExpectedRespHeaders = maps:from_list(RespHeaders),
+ %% The request process executed normally.
+ #{procs := Procs} = Metrics,
+ [{_, #{
+ spawn := ProcSpawn,
+ exit := ProcExit,
+ reason := normal
+ }}] = maps:to_list(Procs),
+ true = ProcSpawn =< ProcExit,
+ %% Confirm other metadata are as expected.
+ #{
+ ref := _,
+ pid := From,
+ streamid := 1,
+ reason := normal,
+ req := #{}
+ } = Metrics,
+ %% All good!
+ ok
+ after 1000 ->
+ error(timeout)
+ end.