-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proxy info messages to the adapter (#316)
- Loading branch information
1 parent
c6dcdf9
commit 5d088f7
Showing
5 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test,integration_test}/**/*.{ex,exs}"] | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test,examples,integration_test}/**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
defmodule InfoTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias TestPool, as: P | ||
alias TestAgent, as: A | ||
alias TestQuery, as: Q | ||
|
||
test "handle_info handles harmless message and moves on" do | ||
stack = [ | ||
fn opts -> | ||
send(opts[:parent], {:connected, self()}) | ||
{:ok, :state} | ||
end, | ||
:ok, | ||
{:idle, :state}, | ||
{:idle, :state} | ||
] | ||
|
||
{:ok, agent} = A.start_link(stack) | ||
{:ok, pool} = P.start_link(agent: agent, parent: self()) | ||
|
||
assert_receive {:connected, conn} | ||
send(conn, "some harmless message") | ||
assert P.run(pool, fn _ -> :result end) == :result | ||
|
||
assert [ | ||
connect: _, | ||
handle_info: _, | ||
handle_status: _, | ||
handle_status: _ | ||
] = A.record(agent) | ||
end | ||
|
||
test "handle_info can force disconnect" do | ||
stack = [ | ||
fn opts -> | ||
send(opts[:parent], {:connected, self()}) | ||
{:ok, :state} | ||
end, | ||
{:disconnect, RuntimeError.exception("TCP connection just closed")}, | ||
:ok, | ||
fn opts -> | ||
send(opts[:parent], :reconnected) | ||
{:ok, :state} | ||
end | ||
] | ||
|
||
{:ok, agent} = A.start_link(stack) | ||
P.start_link(agent: agent, parent: self()) | ||
|
||
assert_receive {:connected, conn} | ||
send(conn, "monitor says TCP connection just closed") | ||
assert_receive :reconnected | ||
|
||
assert [ | ||
connect: _, | ||
handle_info: _, | ||
disconnect: _, | ||
connect: _ | ||
] = A.record(agent) | ||
end | ||
|
||
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, "monitor says TCP connection just closed") | ||
|
||
# This waits for the info message to be processed. | ||
:sys.get_state(conn_pid) | ||
|
||
{:disconnect, RuntimeError.exception("TCP connection is closed"), :new_state} | ||
end, | ||
{:disconnect, RuntimeError.exception("TCP connection just closed")}, | ||
:ok, | ||
fn opts -> | ||
send(opts[:parent], :reconnected) | ||
{:ok, :state} | ||
end | ||
] | ||
|
||
{:ok, agent} = A.start_link(stack) | ||
{:ok, pool} = P.start_link(agent: agent, parent: self()) | ||
|
||
assert {:error, %RuntimeError{message: "TCP connection is closed"}} = | ||
P.execute(pool, %Q{}, []) | ||
|
||
assert_receive :reconnected | ||
|
||
assert [ | ||
connect: _, | ||
handle_execute: _, | ||
handle_info: _, | ||
disconnect: _, | ||
connect: _ | ||
] = A.record(agent) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters