From eaa052616f7c85d4daf4817ceecd5f87fecfc8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 2 Oct 2019 20:30:32 +0200 Subject: Ensure we can stream the response body from any process --- test/handlers/resp_h.erl | 15 +++++++++++++++ test/req_SUITE.erl | 5 +++++ 2 files changed, 20 insertions(+) (limited to 'test') diff --git a/test/handlers/resp_h.erl b/test/handlers/resp_h.erl index 19405db..bc76d56 100644 --- a/test/handlers/resp_h.erl +++ b/test/handlers/resp_h.erl @@ -247,6 +247,21 @@ do(<<"stream_body">>, Req0, Opts) -> cowboy_req:stream_body(<<"Hello! ">>, nofin, Req), cowboy_req:stream_body({sendfile, 0, AppSize, AppFile}, fin, Req), {ok, Req, Opts}; + <<"spawn">> -> + Req = cowboy_req:stream_reply(200, Req0), + Parent = self(), + Pid = spawn(fun() -> + cowboy_req:stream_body(<<"Hello ">>, nofin, Req), + cowboy_req:stream_body(<<"world">>, nofin, Req), + cowboy_req:stream_body(<<"!">>, fin, Req), + Parent ! {self(), ok} + end), + receive + {Pid, ok} -> ok + after 5000 -> + error(timeout) + end, + {ok, Req, Opts}; _ -> %% Call stream_body without initiating streaming. cowboy_req:stream_body(<<0:800000>>, fin, Req0), diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl index 72cc0ed..2cc8de4 100644 --- a/test/req_SUITE.erl +++ b/test/req_SUITE.erl @@ -942,6 +942,11 @@ stream_body_sendfile_fin(Config) -> {200, _, ExpectedBody} = do_get("/resp/stream_body/sendfile_fin", Config), ok. +stream_body_spawn(Config) -> + doc("Confirm we can use cowboy_req:stream_body/3 from another process."), + {200, _, <<"Hello world!">>} = do_get("/resp/stream_body/spawn", Config), + ok. + stream_body_content_length_multiple(Config) -> doc("Streamed body via multiple calls."), {200, _, <<"Hello world!">>} = do_get("/resp/stream_body_content_length/multiple", Config), -- cgit v1.2.3