From: Peter Rabbitson Date: Tue, 29 Jul 2014 03:20:16 +0000 (+0200) Subject: Revert improved test added in b6b8f72f, replace with original from dabe173a X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1016d16752eab3aef8e63f721dddd33ad3638f4e;p=dbsrgits%2FDBIx-Class-Historic.git Revert improved test added in b6b8f72f, replace with original from dabe173a The new test contains a case which it *seems* to me needs to be an exception. Since we are already pretty late with 28, I am just reverting the test alone (while keeping the changes). This way I am not backing myself into a corner with a published test in 29. --- diff --git a/t/prefetch/empty_cache.t b/t/prefetch/empty_cache.t index 6fa4bb9..9f42d5a 100644 --- a/t/prefetch/empty_cache.t +++ b/t/prefetch/empty_cache.t @@ -8,32 +8,32 @@ use DBICTest; my $schema = DBICTest->init_schema(); -my $no_albums_artist = { name => 'We Have No Albums' }; -$schema->resultset('Artist')->create($no_albums_artist); - -foreach ( - [empty => \'0 = 1', 0], - [nonempty => $no_albums_artist, 1], -) { - my ($desc, $cond, $count) = @$_; - - my $artists_rs = $schema->resultset('Artist') - ->search($cond, { prefetch => 'cds', cache => 1 }); - - $schema->is_executed_querycount( sub { - my @artists = $artists_rs->all; - is( 0+@{$artists_rs->get_cache}, $count, "$desc cache on original resultset" ); - is( 0+@artists, $count, "$desc original resultset" ); - }, 1, "->all on $desc original resultset hit db" ); - - $schema->is_executed_querycount( sub { - my $cds_rs = $artists_rs->related_resultset('cds'); - is_deeply( $cds_rs->get_cache, [], 'empty cache on related resultset' ); - - my @cds = $cds_rs->all; - is( 0+@cds, 0, 'empty related resultset' ); - }, 0, '->all on empty related resultest didn\'t hit db' ); -} +my $queries; +my $debugcb = sub { $queries++; }; +my $orig_debug = $schema->storage->debug; + +{ + $queries = 0; + $schema->storage->debugcb($debugcb); + $schema->storage->debug(1); + + my $cds_rs = $schema->resultset('CD') + ->search(\'0 = 1', { prefetch => 'tracks', cache => 1 }); + + my @cds = $cds_rs->all; + is( $queries, 1, '->all on empty original resultset hit db' ); + is_deeply( $cds_rs->get_cache, [], 'empty cache on original resultset' ); + is( 0+@cds, 0, 'empty original resultset' ); + my $tracks_rs = $cds_rs->related_resultset('tracks'); + is_deeply( $tracks_rs->get_cache, [], 'empty cache on related resultset' ); + + my @tracks = $tracks_rs->all; + is( $queries, 1, "->all on empty related resultset didn't hit db" ); + is( 0+@tracks, 0, 'empty related resultset' ); + + $schema->storage->debugcb(undef); + $schema->storage->debug($orig_debug); +} done_testing;