DBIO-PostgreSQL-EV
view release on metacpan or search on metacpan
t/07-pool-connect-replay-unit.t view on Meta::CPAN
$storage->{pool} = FakePool07->new; # no _connection_ready_future -> is_connected path
my $conn = FakeConn07->new;
# bindless connect statement -> query()
$storage->_run_pool_connect_statement($conn, q{SET search_path = myschema}, undef);
is_deeply $conn->{queries}, [ 'SET search_path = myschema' ],
'bindless statement dispatched via query() on the connection';
is_deeply $conn->{params}, [], 'no query_params used for a bindless statement';
# bound connect statement -> query_params() with '?' shaped to '$N'
$storage->_run_pool_connect_statement($conn, q{SELECT set_config('x', ?, false)}, undef, 'v');
is $conn->{queries}[-1], q{SELECT set_config('x', $1, false)},
'bound statement shaped ? -> $1 before dispatch (query_params)';
is_deeply $conn->{params}[-1], [ 'v' ], 'bind value forwarded to query_params';
}
# --- 2b. a failing connect statement fails loud -------------------------------
{
my $storage = DBIO::PostgreSQL::EV::Storage->new(undef);
$storage->{pool} = FakePool07->new;
my $conn = FakeConn07->new;
$conn->{fail} = 'permission denied for schema';
throws_ok {
$storage->_run_pool_connect_statement($conn, q{SET search_path = nope}, undef)
} qr/pool connect statement failed: permission denied/,
'a statement error croaks (fail loud, no silent drop)';
}
# --- 3. full replay dispatch reaches the seam ---------------------------------
# Wire a fake OWNER whose _run_pool_connect_actions replays two actions; assert
# both land on the freshly-spawned connection through our seam.
{
package FakeOwner07;
sub new { bless {}, shift }
# Mirror the core owner contract: hand the runner one ($sql, $attrs, @bind)
# per action. Here: one on_connect_do-style and one on_connect_call-style.
sub _run_pool_connect_actions {
my ($self, $runner) = @_;
$runner->(q{SET myapp.a = 'do'}, undef);
$runner->(q{SET myapp.b = 'call'}, undef);
return $self;
}
}
{
my $storage = DBIO::PostgreSQL::EV::Storage->new(undef);
$storage->{pool} = FakePool07->new;
my $owner = FakeOwner07->new;
$storage->_owner_storage($owner); # held strongly by $owner lexical below
my $conn = FakeConn07->new;
$storage->_setup_pool_connection($conn);
is_deeply $conn->{queries},
[ q{SET myapp.a = 'do'}, q{SET myapp.b = 'call'} ],
'both replayed actions executed on the freshly-spawned connection via the seam';
# keep $owner alive to the end (the storage holds _owner_storage weakly)
ok $owner, 'owner kept in scope';
}
done_testing;
( run in 1.386 second using v1.01-cache-2.11-cpan-aadc1410aed )