diff options
author | Loïc Hoguin <[email protected]> | 2017-09-27 14:17:27 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-09-27 14:17:27 +0200 |
commit | 11ae407eed92002339fc6cde8acd767e7be953c1 (patch) | |
tree | e375c9fa324cd4b9fa988e9a83978064374be54c /test/handlers | |
parent | d47e22edaa1a876081c07bf49c79587c3c2d21d5 (diff) | |
download | cowboy-11ae407eed92002339fc6cde8acd767e7be953c1.tar.gz cowboy-11ae407eed92002339fc6cde8acd767e7be953c1.tar.bz2 cowboy-11ae407eed92002339fc6cde8acd767e7be953c1.zip |
Ensure the behavior on stream handler crash is consistent
Also corrects the lack of error response when HTTP/1.1 is used.
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/stream_handler_h.erl | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/test/handlers/stream_handler_h.erl b/test/handlers/stream_handler_h.erl index 3ee4932..74fc478 100644 --- a/test/handlers/stream_handler_h.erl +++ b/test/handlers/stream_handler_h.erl @@ -21,6 +21,16 @@ init(StreamID, Req, Opts) -> Pid ! {Pid, self(), init, StreamID, Req, Opts}, {init_commands(StreamID, Req, State), State}. +init_commands(_, _, #state{test=crash_in_init}) -> + error(crash); +init_commands(_, _, #state{test=crash_in_data}) -> + []; +init_commands(_, _, #state{test=crash_in_info}) -> + []; +init_commands(_, _, #state{test=crash_in_terminate}) -> + [{response, 200, #{<<"content-length">> => <<"12">>}, <<"Hello world!">>}, stop]; +init_commands(_, _, #state{test=crash_in_early_error}) -> + error(crash); init_commands(_, _, State=#state{test=shutdown_on_stream_stop}) -> Spawn = init_process(false, State), [{headers, 200, #{}}, {spawn, Spawn, 5000}, stop]; @@ -50,20 +60,32 @@ init_process(TrapExit, #state{pid=Pid}) -> receive {Spawn, ready} -> ok after 1000 -> error(timeout) end, Spawn. +data(_, _, _, #state{test=crash_in_data}) -> + error(crash); data(StreamID, IsFin, Data, State=#state{pid=Pid}) -> Pid ! {Pid, self(), data, StreamID, IsFin, Data, State}, {[], State}. +info(_, Resp={response, _, _, _}, State) -> + {[Resp], State}; +info(_, crash, #state{test=crash_in_info}) -> + error(crash); info(StreamID, Info, State=#state{pid=Pid}) -> Pid ! {Pid, self(), info, StreamID, Info, State}, {[], State}. +terminate(StreamID, Reason, State=#state{pid=Pid, test=crash_in_terminate}) -> + Pid ! {Pid, self(), terminate, StreamID, Reason, State}, + error(crash); terminate(StreamID, Reason, State=#state{pid=Pid}) -> Pid ! {Pid, self(), terminate, StreamID, Reason, State}, ok. -%% This clause can only test for early errors that reached the required header. +%% This clause can only test for early errors that reached the required headers. early_error(StreamID, Reason, PartialReq, Resp, Opts) -> Pid = list_to_pid(binary_to_list(cowboy_req:header(<<"x-test-pid">>, PartialReq))), Pid ! {Pid, self(), early_error, StreamID, Reason, PartialReq, Resp, Opts}, - Resp. + case cowboy_req:header(<<"x-test-case">>, PartialReq) of + <<"crash_in_early_error",_/bits>> -> error(crash); + _ -> Resp + end. |