0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Add a test for stream_reply metrics

This commit is contained in:
Loïc Hoguin 2017-10-21 21:03:06 +01:00
parent 76f4db863e
commit debaecd49a
No known key found for this signature in database
GPG key ID: 71366FF21851DF03

View file

@ -68,7 +68,8 @@ init_routes(_) -> [
{"localhost", [
{"/", hello_h, []},
{"/default", default_h, []},
{"/full/:key", echo_h, []}
{"/full/:key", echo_h, []},
{"/resp/:key[/:arg]", resp_h, []}
]}
].
@ -87,9 +88,12 @@ do_metrics_callback() ->
hello_world(Config) ->
doc("Confirm metrics are correct for a normal GET request."),
do_get("/", Config).
do_get(Path, Config) ->
%% Perform a GET request.
ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/", [
Ref = gun:get(ConnPid, Path, [
{<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())}
]),
@ -119,7 +123,9 @@ hello_world(Config) ->
resp_headers := ExpectedRespHeaders,
resp_body_length := RespBodyLen
} = Metrics,
ExpectedRespHeaders = maps:from_list(RespHeaders),
%% The transfer-encoding header is hidden from stream handlers.
ExpectedRespHeaders = maps:remove(<<"transfer-encoding">>,
maps:from_list(RespHeaders)),
true = byte_size(RespBody) > 0,
true = RespBodyLen > 0,
%% The request process executed normally.
@ -300,3 +306,8 @@ do_early_error(Config) ->
after 1000 ->
error(timeout)
end.
%% This test is identical to normal GET except for the handler.
stream_reply(Config) ->
doc("Confirm metrics are correct for long polling."),
do_get("/resp/stream_reply2/200", Config).