aboutsummaryrefslogtreecommitdiffstats
path: root/test/metrics_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-21 14:56:28 +0100
committerLoïc Hoguin <[email protected]>2017-10-21 14:56:28 +0100
commitc4651261b652ce2727b9181ef171ce7ca6add1b6 (patch)
treebbe3fd7696e0d39964e139e7af0974db2d497eb4 /test/metrics_SUITE.erl
parent2a905e9bda3df9260602fb68e9415a3ad4e0cecb (diff)
downloadcowboy-c4651261b652ce2727b9181ef171ce7ca6add1b6.tar.gz
cowboy-c4651261b652ce2727b9181ef171ce7ca6add1b6.tar.bz2
cowboy-c4651261b652ce2727b9181ef171ce7ca6add1b6.zip
Add a test for early_error metrics
Diffstat (limited to 'test/metrics_SUITE.erl')
-rw-r--r--test/metrics_SUITE.erl47
1 files changed, 45 insertions, 2 deletions
diff --git a/test/metrics_SUITE.erl b/test/metrics_SUITE.erl
index b43e475..33b60bd 100644
--- a/test/metrics_SUITE.erl
+++ b/test/metrics_SUITE.erl
@@ -73,7 +73,11 @@ init_routes(_) -> [
].
do_metrics_callback() ->
- fun(Metrics=#{req := #{headers := #{<<"x-test-pid">> := PidBin}}}) ->
+ fun(Metrics) ->
+ PidBin = case Metrics of
+ #{req := #{headers := #{<<"x-test-pid">> := P}}} -> P;
+ #{partial_req := #{headers := #{<<"x-test-pid">> := P}}} -> P
+ end,
Pid = list_to_pid(binary_to_list(PidBin)),
Pid ! {metrics, self(), Metrics},
ok
@@ -203,7 +207,7 @@ post_body(Config) ->
end.
no_resp_body(Config) ->
- doc("Confirm metrics are correct for a 204 response to a GET request."),
+ doc("Confirm metrics are correct for a default 204 response to a GET request."),
%% Perform a GET request.
ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/default", [
@@ -257,3 +261,42 @@ no_resp_body(Config) ->
after 1000 ->
error(timeout)
end.
+
+early_error(Config) ->
+ case config(protocol, Config) of
+ http -> do_early_error(Config);
+ http2 -> doc("The callback early_error/5 is not currently used for HTTP/2.")
+ end.
+
+do_early_error(Config) ->
+ doc("Confirm metrics are correct for an early_error response."),
+ %% Perform a malformed GET request.
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, "/", [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"host">>, <<"host:port">>},
+ {<<"x-test-pid">>, pid_to_list(self())}
+ ]),
+ {response, fin, 400, RespHeaders} = gun:await(ConnPid, Ref),
+ gun:close(ConnPid),
+ %% Receive the metrics and validate them.
+ receive
+ {metrics, From, Metrics} ->
+ %% Confirm the metadata is there as expected.
+ #{
+ ref := _,
+ pid := From,
+ streamid := 1,
+ reason := {stream_error, 1, protocol_error, _},
+ partial_req := #{},
+ resp_status := 400,
+ resp_headers := ExpectedRespHeaders,
+ early_error_time := _,
+ resp_body_length := 0
+ } = Metrics,
+ ExpectedRespHeaders = maps:from_list(RespHeaders),
+ %% All good!
+ ok
+ after 1000 ->
+ error(timeout)
+ end.