Open wojtekmach opened 1 year ago
Oh no, I just realised there's a Plug.Conn.register_before_chunk/2
on main which I can totally use instead. Sorry about that!
Given register_before_chunk got reverted, can I pursue this?
Sounds good to me!
Turns out process messaging isn't a great fit for my main use case for this which is Req :plug adapter. The reason is if someone ends up with something like this:
test "foo" do
defmodule Foo do
use GenServer
def start_link(arg) do
GenServer.start_link(__MODULE__, arg)
end
@impl true
def init(_) do
Req.get!(
plug: fn conn ->
Plug.Conn.send_resp(conn, 200, "ok")
end
)
{:ok, %{}}
end
end
start_supervised!(Foo)
Process.sleep(100)
end
The GenServer ends up receiving these Plug.Test messages which is unexpected. This was reported in https://github.com/wojtekmach/req/issues/316 and I fixed it in Req by consuming these.
In any case, I'd be still keen on a Plug.Test.sent_chunks
function that receives accumulated chunks stored in the adapter state as mentioned in the PR description.
Before this patch there was no way to reconstruct the invidual chunks that were sent. All we got was the full resulting body in
conn.resp_body
.For completeness, I believe instead of messaging we could store chunks in a list in the test adapter state and simply append:
but I was following the existing functions
sent_informs
andsent_upgrades
.My use case is to be able to test response streaming using Req :plug adapter: