Skip to content

Commit

Permalink
make test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Nov 11, 2024
1 parent 595439a commit a3ece3c
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions integration_test/cases/info_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
defmodule InfoTest do
use ExUnit.Case, async: true

alias TestPool, as: P
alias TestAgent, as: A
alias TestQuery, as: Q

test "handle_info handles message and moves on" do
stack = [
Expand Down Expand Up @@ -47,7 +49,7 @@ defmodule InfoTest do
P.start_link(agent: agent, parent: self())

assert_receive {:connected, conn}
send(conn, "some harmful message")
send(conn, "some harmful message that casuses disconnect")
assert_receive :reconnected

assert [
Expand All @@ -58,5 +60,43 @@ defmodule InfoTest do
] = A.record(agent)
end

test "handle_info's disconnect with connection checked out"
test "handle_info's disconnect while checked out client crashes is no-op" do
stack = [
fn _opts ->
{:ok, %{conn_pid: self()}}
end,
fn _query, _params, _opts, %{conn_pid: conn_pid} ->
send(
conn_pid,
"some harmful message that causes disconnect while conneciton is checked out"
)

# This waits for the info message to be processed in the connection.
:sys.get_state(conn_pid)
{:disconnect, :closed, :new_state}
end,
{:disconnect, :closed},
:ok,
fn opts ->
send(opts[:parent], :reconnected)
{:ok, :state}
end
]

parent = self()

{:ok, agent} = A.start_link(stack)
{:ok, pool} = P.start_link(agent: agent, parent: parent)

assert {:error, :closed} = P.execute(pool, %Q{}, [:first])
assert_receive :reconnected

assert [
connect: _,
handle_execute: _,
handle_info: _,
disconnect: _,
connect: _
] = A.record(agent)
end
end

0 comments on commit a3ece3c

Please sign in to comment.