Skip to content

Commit

Permalink
Disconnect actual db connection on terminate (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski committed Oct 14, 2023
1 parent af0f10b commit 72be402
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 33 deletions.
8 changes: 6 additions & 2 deletions integration_test/cases/after_connect_test.exs
Expand Up @@ -183,6 +183,7 @@ defmodule AfterConnectTest do
end,
{:idle, :state},
:oops,
:ok,
fn _ ->
:timer.sleep(:infinity)
end
Expand Down Expand Up @@ -225,7 +226,8 @@ defmodule AfterConnectTest do
assert [
{:connect, _},
{:handle_status, _},
{:handle_execute, [%Q{}, [:after_connect], _, :state]} | _
{:handle_execute, [%Q{}, [:after_connect], _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand All @@ -240,6 +242,7 @@ defmodule AfterConnectTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
fn _ ->
:timer.sleep(:infinity)
end
Expand Down Expand Up @@ -274,7 +277,8 @@ defmodule AfterConnectTest do
assert [
{:connect, _},
{:handle_status, _},
{:handle_execute, [%Q{}, [:after_connect], _, :state]} | _
{:handle_execute, [%Q{}, [:after_connect], _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down
2 changes: 2 additions & 0 deletions integration_test/cases/client_test.exs
Expand Up @@ -220,6 +220,7 @@ defmodule ClientTest do
fn _, _, _, _ ->
throw(:oops)
end,
:ok,
fn opts ->
send(opts[:parent], :reconnected)
{:ok, :new_state}
Expand Down Expand Up @@ -262,6 +263,7 @@ defmodule ClientTest do
{:connect, _},
{:handle_status, _},
{:handle_execute, [%Q{}, [:first], _, :state]},
{:disconnect, _},
{:connect, _},
{:handle_status, _},
{:handle_status, _},
Expand Down
4 changes: 3 additions & 1 deletion integration_test/cases/close_test.exs
Expand Up @@ -131,6 +131,7 @@ defmodule CloseTest do
fn _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -163,7 +164,8 @@ defmodule CloseTest do

assert [
{:connect, [_]},
{:handle_close, [%Q{}, _, :state]} | _
{:handle_close, [%Q{}, _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down
12 changes: 9 additions & 3 deletions integration_test/cases/execute_test.exs
Expand Up @@ -191,6 +191,7 @@ defmodule ExecuteTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -227,7 +228,8 @@ defmodule ExecuteTest do

assert [
{:connect, [_]},
{:handle_execute, [%Q{}, [:param], _, :state]} | _
{:handle_execute, [%Q{}, [:param], _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down Expand Up @@ -354,6 +356,7 @@ defmodule ExecuteTest do
{:ok, :state}
end,
:oops,
:ok,
{:ok, :state}
]

Expand Down Expand Up @@ -382,7 +385,8 @@ defmodule ExecuteTest do

assert [
{:connect, _},
{:handle_execute, [%Q{}, [:param], _, :state]} | _
{:handle_execute, [%Q{}, [:param], _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand All @@ -396,6 +400,7 @@ defmodule ExecuteTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state}
]

Expand All @@ -418,7 +423,8 @@ defmodule ExecuteTest do

assert [
{:connect, _},
{:handle_execute, [%Q{}, [:param], _, :state]} | _
{:handle_execute, [%Q{}, [:param], _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end
end
8 changes: 6 additions & 2 deletions integration_test/cases/prepare_execute_test.exs
Expand Up @@ -211,6 +211,7 @@ defmodule PrepareExecuteTest do
fn _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -247,7 +248,8 @@ defmodule PrepareExecuteTest do

assert [
{:connect, [_]},
{:handle_prepare, [%Q{}, _, :state]} | _
{:handle_prepare, [%Q{}, _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down Expand Up @@ -399,6 +401,7 @@ defmodule PrepareExecuteTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -436,7 +439,8 @@ defmodule PrepareExecuteTest do
assert [
{:connect, [_]},
{:handle_prepare, [%Q{}, _, :state]},
{:handle_execute, [%Q{}, [:param], _, :new_state]} | _
{:handle_execute, [%Q{}, [:param], _, :new_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down
8 changes: 6 additions & 2 deletions integration_test/cases/prepare_stream_test.exs
Expand Up @@ -263,6 +263,7 @@ defmodule PrepareStreamTest do
end,
{:ok, :began, :new_state},
:oops,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -299,7 +300,8 @@ defmodule PrepareStreamTest do
assert [
{:connect, _},
{:handle_begin, [_, :state]},
{:handle_prepare, [%Q{}, _, :new_state]} | _
{:handle_prepare, [%Q{}, _, :new_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand All @@ -315,6 +317,7 @@ defmodule PrepareStreamTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -345,7 +348,8 @@ defmodule PrepareStreamTest do
{:connect, _},
{:handle_begin, [_, :state]},
{:handle_prepare, [%Q{}, _, :new_state]},
{:handle_declare, [%Q{}, [:param], _, :newer_state]} | _
{:handle_declare, [%Q{}, [:param], _, :newer_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down
4 changes: 3 additions & 1 deletion integration_test/cases/prepare_test.exs
Expand Up @@ -167,6 +167,7 @@ defmodule PrepareTest do
fn _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -203,7 +204,8 @@ defmodule PrepareTest do

assert [
{:connect, [_]},
{:handle_prepare, [%Q{}, _, :state]} | _
{:handle_prepare, [%Q{}, _, :state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down
16 changes: 12 additions & 4 deletions integration_test/cases/stream_test.exs
Expand Up @@ -409,6 +409,7 @@ defmodule StreamTest do
end,
{:ok, :began, :new_state},
:oops,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -445,7 +446,8 @@ defmodule StreamTest do
assert [
{:connect, _},
{:handle_begin, [_, :state]},
{:handle_declare, [%Q{}, [:param], _, :new_state]} | _
{:handle_declare, [%Q{}, [:param], _, :new_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand All @@ -460,6 +462,7 @@ defmodule StreamTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -489,7 +492,8 @@ defmodule StreamTest do
assert [
{:connect, _},
{:handle_begin, [_, :state]},
{:handle_declare, [%Q{}, [:param], _, :new_state]} | _
{:handle_declare, [%Q{}, [:param], _, :new_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down Expand Up @@ -540,6 +544,7 @@ defmodule StreamTest do
{:ok, :began, :new_state},
{:ok, %Q{}, %C{}, :newer_state},
:oops,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -577,7 +582,8 @@ defmodule StreamTest do
{:connect, _},
{:handle_begin, [_, :state]},
{:handle_declare, [%Q{}, [:param], _, :new_state]},
{:handle_fetch, [%Q{}, %C{}, _, :newer_state]} | _
{:handle_fetch, [%Q{}, %C{}, _, :newer_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand All @@ -594,6 +600,7 @@ defmodule StreamTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state2}
]

Expand Down Expand Up @@ -625,7 +632,8 @@ defmodule StreamTest do
{:handle_begin, [_, :state]},
{:handle_declare, [%Q{}, [:param], _, :new_state]},
{:handle_fetch, [%Q{}, %C{}, _, :newer_state]},
{:handle_deallocate, [%Q{}, %C{}, _, :newest_state]} | _
{:handle_deallocate, [%Q{}, %C{}, _, :newest_state]},
{:disconnect, _} | _
] = A.record(agent)
end
end
8 changes: 6 additions & 2 deletions integration_test/cases/transaction_execute_test.exs
Expand Up @@ -189,6 +189,7 @@ defmodule TransactionExecuteTest do
end,
{:ok, :began, :new_state},
:oops,
:ok,
{:ok, :state}
]

Expand Down Expand Up @@ -226,7 +227,8 @@ defmodule TransactionExecuteTest do
assert [
{:connect, _},
{:handle_begin, [_, :state]},
{:handle_execute, [%Q{}, [:param], _, :new_state]} | _
{:handle_execute, [%Q{}, [:param], _, :new_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand All @@ -241,6 +243,7 @@ defmodule TransactionExecuteTest do
fn _, _, _, _ ->
raise "oops"
end,
:ok,
{:ok, :state}
]

Expand Down Expand Up @@ -275,7 +278,8 @@ defmodule TransactionExecuteTest do
assert [
{:connect, _},
{:handle_begin, [_, :state]},
{:handle_execute, [%Q{}, [:param], _, :new_state]} | _
{:handle_execute, [%Q{}, [:param], _, :new_state]},
{:disconnect, _} | _
] = A.record(agent)
end

Expand Down

0 comments on commit 72be402

Please sign in to comment.