From: Peter Rabbitson Date: Fri, 8 Jan 2010 14:52:46 +0000 (+0000) Subject: Weird test failures X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=551e711a765052e8bdcb4ab704b5e05c5422330b;p=dbsrgits%2FDBIx-Class-Historic.git Weird test failures --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 3aa429a..1121682 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -5,7 +5,7 @@ use warnings; use DBIx::Class::Exception; use Carp::Clan qw/^DBIx::Class/; -use Scalar::Util qw/weaken/; +use Scalar::Util (); use File::Spec; use Sub::Name (); use Module::Find(); @@ -1295,7 +1295,7 @@ sub _register_source { $source = $source->new({ %$source, source_name => $moniker }); $source->schema($self); - weaken($source->{schema}) if ref($self); + Scalar::Util::weaken($source->{schema}) if ref($self); my $rs_class = $source->result_class; diff --git a/t/52cycle.t b/t/52cycle.t index 8be1768..145ad92 100644 --- a/t/52cycle.t +++ b/t/52cycle.t @@ -8,16 +8,36 @@ BEGIN { eval { require Test::Memory::Cycle; require Devel::Cycle }; if ($@ or Devel::Cycle->VERSION < 1.10) { plan skip_all => "leak test needs Test::Memory::Cycle and Devel::Cycle >= 1.10"; - } else { - plan tests => 1; - } + }; } use DBICTest; use DBICTest::Schema; +use Scalar::Util (); import Test::Memory::Cycle; -my $s = DBICTest::Schema->clone; +my $weak; -memory_cycle_ok($s, 'No cycles in schema'); +{ + my $s = $weak->{schema} = DBICTest->init_schema; + memory_cycle_ok($s, 'No cycles in schema'); + + my $rs = $weak->{resultset} = $s->resultset ('Artist'); + memory_cycle_ok($rs, 'No cycles in resultset'); + + my $rsrc = $weak->{resultsource} = $rs->result_source; + memory_cycle_ok($rsrc, 'No cycles in resultsource'); + + my $row = $weak->{row} = $rs->first; + memory_cycle_ok($row, 'No cycles in row'); + + Scalar::Util::weaken ($_) for values %$weak; + memory_cycle_ok($weak, 'No cycles in weak object collection'); +} + +for (keys %$weak) { + ok (! $weak->{$_}, "No $_ leaks"); +} + +done_testing; diff --git a/t/schema/anon.t b/t/schema/anon.t new file mode 100644 index 0000000..4d74ace --- /dev/null +++ b/t/schema/anon.t @@ -0,0 +1,13 @@ +use strict; +use warnings; +use Test::More; +use Test::Exception; + +use lib qw(t/lib); +use DBICTest; + +lives_ok (sub { + DBICTest->init_schema()->resultset('Artist')->find({artistid => 1 })->update({name => 'anon test'}); +}, 'Schema object not lost in chaining'); + +done_testing;