DBIO-MySQL-EV
view release on metacpan or search on metacpan
t/07-pool-connect-replay-unit.t view on Meta::CPAN
{
my $storage = DBIO::MySQL::EV::Storage->new(undef);
my $conn = FakeConn07->new;
# bindless connect statement -> query()
$storage->_run_pool_connect_statement($conn, q{SET time_zone = '+00:00'}, undef);
is_deeply $conn->{queries}, [ q{SET time_zone = '+00:00'} ],
'bindless statement dispatched via query() on the connection';
is_deeply $conn->{params}, [], 'no prepare/execute binds for a bindless statement';
# bound connect statement -> prepare + execute with '?' LEFT AS '?' (native)
$storage->_run_pool_connect_statement($conn, q{SELECT set_myvar(?)}, undef, 'v');
is $conn->{queries}[-1], q{SELECT set_myvar(?)},
'bound statement keeps its ? placeholder (MySQL native -- no ?->$N rewrite)';
is_deeply $conn->{params}[-1], [ 'v' ], 'bind value forwarded to execute()';
}
# --- 2b. a failing connect statement fails loud -------------------------------
{
my $storage = DBIO::MySQL::EV::Storage->new(undef);
my $conn = FakeConn07->new;
$conn->{fail} = 'Access denied for user';
throws_ok {
$storage->_run_pool_connect_statement($conn, q{SET sql_mode = 'STRICT'}, undef)
} qr/pool connect statement failed: Access 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 time_zone = '+00:00'}, undef);
$runner->(q{SET sql_mode = 'TRADITIONAL'}, undef);
return $self;
}
}
{
my $storage = DBIO::MySQL::EV::Storage->new(undef);
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 time_zone = '+00:00'}, q{SET sql_mode = 'TRADITIONAL'} ],
'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 0.854 second using v1.01-cache-2.11-cpan-14f38c9f855 )