Skip to content

Commit 263b350

Browse files
authored
Retry status after disconnect (#353)
1 parent e5d6969 commit 263b350

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

integration_test/cases/transaction_test.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,37 @@ defmodule TransactionTest do
11871187
] = A.record(agent)
11881188
end
11891189

1190+
test "status disconnect_and_retry succeeds" do
1191+
err = RuntimeError.exception("oops")
1192+
1193+
stack = [
1194+
{:ok, :state},
1195+
{:disconnect_and_retry, err, :new_state},
1196+
:ok,
1197+
fn opts ->
1198+
send(opts[:parent], :reconnected)
1199+
{:ok, :reconnected_state}
1200+
end,
1201+
{:idle, :newest_state}
1202+
]
1203+
1204+
{:ok, agent} = A.start_link(stack)
1205+
1206+
opts = [agent: agent, parent: self()]
1207+
{:ok, pool} = P.start_link(opts)
1208+
1209+
assert P.status(pool, opts) == :idle
1210+
assert_receive :reconnected
1211+
1212+
assert [
1213+
connect: [_],
1214+
handle_status: [_, :state],
1215+
disconnect: [^err, :new_state],
1216+
connect: [_],
1217+
handle_status: [_, :reconnected_state]
1218+
] = A.record(agent)
1219+
end
1220+
11901221
test "status returns result on successful run" do
11911222
stack = [
11921223
{:ok, :state},

lib/db_connection.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ defmodule DBConnection do
19271927

19281928
other ->
19291929
case retry_or_handle_common_result(other, conn, meter) do
1930+
{:retry, _, _} = retry -> retry
19301931
{:error, _, meter} -> {:ok, :error, meter}
19311932
{kind, reason, stack, _meter} -> :erlang.raise(kind, reason, stack)
19321933
_ -> other

0 commit comments

Comments
 (0)