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

Keep the state returned by the tracer callback

It was mistakenly discarded.
This commit is contained in:
Loïc Hoguin 2017-11-10 14:59:11 +00:00
parent 32d9d494c7
commit 6cc162583d
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
2 changed files with 26 additions and 8 deletions

View file

@ -98,12 +98,13 @@ do_tracer_callback(Pid) ->
fun
(Event, _) when Event =:= init; Event =:= terminate ->
Pid ! Event,
undefined;
0;
(Event={trace_ts, _, call, {cowboy_req, reply, _}, _}, State) ->
Pid ! Event,
State;
Pid ! {state, State},
State + 1;
(_, State) ->
State
State + 1
end.
%% Tests.
@ -140,6 +141,23 @@ terminate(Config) ->
error(timeout)
end.
state(Config) ->
doc("Ensure the returned state is used."),
Ref = config(ref, Config),
Opts = ranch:get_protocol_options(Ref),
ranch:set_protocol_options(Ref, Opts#{
tracer_callback => do_tracer_callback(self()),
tracer_match_specs => [fun(_,_,_) -> true end]
}),
do_get("/", Config),
receive
{state, St} ->
true = St > 0,
ok
after 100 ->
error(timeout)
end.
empty(Config) ->
doc("Empty match specs unconditionally enable tracing."),
Ref = config(ref, Config),