Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for async requests #228

Merged
merged 34 commits into from
Jun 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9daf971
ci: fix elixir.yml indentation
zachallaun May 30, 2023
8adbf5d
ci: update elixir version and add otp 26
zachallaun May 30, 2023
8aee995
wip: overly simple first pass at `Finch.async_request/3`
zachallaun May 30, 2023
785616c
wip: `Finch.cancel_async_request/2` (test failing)
zachallaun May 31, 2023
bb3beaa
wip: push async api to the adapters
zachallaun Jun 2, 2023
186385e
test: more reliable tests & test async cancel with http1 pool
zachallaun Jun 3, 2023
fc97489
fix: exit async req process if caller exits
zachallaun Jun 3, 2023
5cbba4e
test: add tests for success and error async requests to http1 pool test
zachallaun Jun 3, 2023
4f7e31e
refactor: use request_ref in existing http2 pool messages
zachallaun Jun 3, 2023
00e1752
refactor: use request_ref to cancel http2 requests
zachallaun Jun 3, 2023
f29b841
wip: implement async_request & cancelation for http2
zachallaun Jun 4, 2023
69d37d6
refactor: unify sync and async http2 request flow
zachallaun Jun 4, 2023
0b65bc8
refactor: clean up http2 request handling
zachallaun Jun 4, 2023
e43a005
fix: return consistent errors in http2 pool
zachallaun Jun 4, 2023
6632115
test(http2): add async request tests for error conditions
zachallaun Jun 6, 2023
8968a2e
test: only start finch and server when needed
zachallaun Jun 6, 2023
4d63e0b
fix(http2): cancel async requests if calling pid exits
zachallaun Jun 6, 2023
a1f81d2
test(http1): improve flaky pool tests
zachallaun Jun 6, 2023
7af3595
docs: improve docs and typespecs for `async_request/3`
zachallaun Jun 6, 2023
42d3fbe
test: no doctests on main module
zachallaun Jun 7, 2023
6e75444
test: http2 telemetry + always detach telemetry after test
zachallaun Jun 7, 2023
3142972
fix: don't send `{ref, :ok}` to async requests callers
zachallaun Jun 7, 2023
cf3e822
refactor: clean up http2 pool request sending
zachallaun Jun 7, 2023
c12aeec
fix: cancel http2 request when in connected_read_only
zachallaun Jun 8, 2023
efdb914
refactor: don't store extra state in request stream struct
zachallaun Jun 8, 2023
1289f7d
docs: note which telemetry events are http1-only
zachallaun Jun 8, 2023
d4f86b5
refactor: rename internal helper
zachallaun Jun 8, 2023
8bae1ce
chore: split out request_opt type from request_opts
zachallaun Jun 11, 2023
9ae43ef
chore: spawn linked async req process in http1 pool
zachallaun Jun 11, 2023
f89106b
refactor: simplify request_ref structure
zachallaun Jun 11, 2023
83b538a
test: test async cancelation when caller exits normally or abnormally
zachallaun Jun 11, 2023
f53e8e4
docs: additional documentation for async requests
zachallaun Jun 11, 2023
4d259b6
test: less finicky http1 pool tests
zachallaun Jun 11, 2023
aa2ced7
remove otp 26 from test matrix due to unexpected changes in ssl optio…
sneako Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: only start finch and server when needed
zachallaun committed Jun 6, 2023
commit 8968a2e8da0a6eca37fe39af5542b5d97d34364e
65 changes: 38 additions & 27 deletions test/finch/http2/pool_test.exs
Original file line number Diff line number Diff line change
@@ -272,32 +272,10 @@ defmodule Finch.HTTP2.PoolTest do
end

describe "async requests" do
setup %{test: finch_name} do
start_supervised!(
{Finch,
name: finch_name,
pools: %{
default: [
protocol: :http2,
count: 5,
conn_opts: [
transport_opts: [
verify: :verify_none
]
]
]
}}
)

port = 4006
url = "https://localhost:#{port}"
test "sends responses to the caller", %{test: finch_name} do
start_finch!(finch_name)
{:ok, url} = start_server!()

start_supervised!({HTTP2Server, port: port})

{:ok, finch_name: finch_name, url: url}
end

test "sends responses to the caller", %{finch_name: finch_name, url: url} do
request_ref =
Finch.build(:get, url)
|> Finch.async_request(finch_name)
@@ -308,15 +286,21 @@ defmodule Finch.HTTP2.PoolTest do
assert_receive {^request_ref, :done}
end

test "sends errors to the caller", %{finch_name: finch_name, url: url} do
test "sends errors to the caller", %{test: finch_name} do
start_finch!(finch_name)
{:ok, url} = start_server!()

request_ref =
Finch.build(:get, url <> "/wait/100")
|> Finch.async_request(finch_name, receive_timeout: 10)

assert_receive {^request_ref, {:error, %{reason: :request_timeout}}}, 300
end

test "canceled with cancel_async_request/1", %{finch_name: finch_name, url: url} do
test "canceled with cancel_async_request/1", %{test: finch_name} do
start_finch!(finch_name)
{:ok, url} = start_server!()

ref =
Finch.build(:get, url <> "/stream/1/50")
|> Finch.async_request(finch_name)
@@ -409,6 +393,33 @@ defmodule Finch.HTTP2.PoolTest do

assert_receive {^ref, {:error, %{reason: {:max_header_list_size_exceeded, _, _}}}}
end

defp start_finch!(finch_name) do
start_supervised!(
{Finch,
name: finch_name,
pools: %{
default: [
protocol: :http2,
count: 5,
conn_opts: [
transport_opts: [
verify: :verify_none
]
]
]
}}
)
end

defp start_server! do
port = 4006
url = "https://localhost:#{port}"

start_supervised!({HTTP2Server, port: port})

{:ok, url}
end
end

@pdict_key {__MODULE__, :http2_test_server}