0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00
cowboy/test/handlers/crash_h.erl
Hubert Łępicki dbc02ed92e [1551] Handle external exits of processes
Adds handler to capture external exits of processes, and tests to verify
this is indeed happening.

Problem: I don't know how to silence crash reports in this case. When I
run the tests, I can see the crash reports I added, but I would like to
silence them in tests. ct_helper:ignore() doesn't seem to cut it the way
I use it, which is probably wrong. I see on the console:

Testing ninenines.cowboy.metrics_SUITE: Starting test, 96 test cases

=ERROR REPORT==== 23-Apr-2021::11:22:09 ===
Ranch listener http, connection process <0.266.0>, stream 1 had its
request process <0.275.0> exit with reason external_exit

which we probably want to silence but I'm not sure how. Help?
2021-04-23 11:22:44 +02:00

22 lines
494 B
Erlang

%% This module crashes immediately.
-module(crash_h).
-behaviour(cowboy_handler).
-export([init/2]).
-spec init(_, _) -> no_return().
init(_, no_reply) ->
ct_helper:ignore(?MODULE, init, 2),
error(crash);
init(Req, reply) ->
_ = cowboy_req:reply(200, Req),
ct_helper:ignore(?MODULE, init, 2),
error(crash);
init(_, internal_exit) ->
ct_helper:ignore(?MODULE, init, 2),
exit(internal_exit);
init(_, external_exit) ->
ct_helper:ignore(?MODULE, init, 2),
exit(self(), external_exit).