DBIx-Class
view release on metacpan or search on metacpan
t/52leaks.t view on Meta::CPAN
CORE::bless( $_[0], (@_ > 1) ? $_[1] : caller() );
};
*CORE::GLOBAL::bless = sub { goto $bless_override };
}
use strict;
use warnings;
use Test::More;
use lib qw(t/lib);
use DBICTest::RunMode;
use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistry visit_refs);
use Scalar::Util qw(weaken blessed reftype);
use DBIx::Class::_Util qw(hrefaddr sigwarn_silencer modver_gt_or_eq modver_gt_or_eq_and_lt);
BEGIN {
plan skip_all => "Your perl version $] appears to leak like a sieve - skipping test"
if DBIx::Class::_ENV_::PEEPEENESS;
}
my $TB = Test::More->builder;
if ($ENV{DBICTEST_IN_PERSISTENT_ENV}) {
# without this explicit close TB warns in END after a ->reset
close ($TB->$_) for qw(output failure_output todo_output);
# newer TB does not auto-reopen handles
if ( modver_gt_or_eq( 'Test::More', '1.200' ) ) {
open ($TB->$_, '>&', *STDERR)
for qw( failure_output todo_output );
open ($TB->output, '>&', *STDOUT);
}
# so done_testing can work on every persistent pass
$TB->reset;
}
# this is what holds all weakened refs to be checked for leakage
my $weak_registry = {};
# whether or to invoke IC::DT
my $has_dt;
# Skip the heavy-duty leak tracing when just doing an install
unless (DBICTest::RunMode->is_plain) {
# redefine the bless override so that we can catch each and every object created
no warnings qw/redefine once/;
no strict qw/refs/;
$bless_override = sub {
my $obj = CORE::bless(
$_[0], (@_ > 1) ? $_[1] : do {
my ($class, $fn, $line) = caller();
fail ("bless() of $_[0] into $class without explicit class specification at $fn line $line")
if $class =~ /^ (?: DBIx\:\:Class | DBICTest ) /x;
$class;
}
);
# unicode is tricky, and now we happen to invoke it early via a
# regex in connection()
return $obj if (ref $obj) =~ /^utf8/;
# Test Builder is now making a new object for every pass/fail (que bloat?)
# and as such we can't really store any of its objects (since it will
# re-populate the registry while checking it, ewwww!)
return $obj if (ref $obj) =~ /^TB2::|^Test::Stream/;
# populate immediately to avoid weird side effects
return populate_weakregistry ($weak_registry, $obj );
};
require Try::Tiny;
for my $func (qw/try catch finally/) {
my $orig = \&{"Try::Tiny::$func"};
*{"Try::Tiny::$func"} = sub (&;@) {
populate_weakregistry( $weak_registry, $_[0] );
goto $orig;
}
}
# Some modules are known to install singletons on-load
# Load them and empty the registry
# this loads the DT armada
$has_dt = DBIx::Class::Optional::Dependencies->req_ok_for('test_dt_sqlite');
require Errno;
require DBI;
require DBD::SQLite;
require FileHandle;
require Moo;
%$weak_registry = ();
}
{
use_ok ('DBICTest');
my $schema = DBICTest->init_schema;
my $rs = $schema->resultset ('Artist');
my $storage = $schema->storage;
ok ($storage->connected, 'we are connected');
my $row_obj = $rs->search({}, { rows => 1})->next; # so that commits/rollbacks work
ok ($row_obj, 'row from db');
# txn_do to invoke more codepaths
my ($mc_row_obj, $pager, $pager_explicit_count) = $schema->txn_do (sub {
my $artist = $schema->resultset('Artist')->create ({
name => 'foo artist',
cds => [{
title => 'foo cd',
year => 1984,
tracks => [
{ title => 't1' },
{ title => 't2' },
],
( run in 2.643 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )