X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F84serialize.t;h=ffa63fa0f50da17d4b1175da2770dde32edf7770;hb=fcdd56ca536a7751e2cf5a2c9ba62424c7f18122;hp=dedf8daebdb0d5128e7ee42590fc8ab1033dddbd;hpb=4376a1574bc5b25f4b9160e8fc3ce329ae226e0f;p=dbsrgits%2FDBIx-Class.git diff --git a/t/84serialize.t b/t/84serialize.t index dedf8da..ffa63fa 100644 --- a/t/84serialize.t +++ b/t/84serialize.t @@ -7,9 +7,10 @@ use lib qw(t/lib); use DBICTest; use Storable qw(dclone freeze nfreeze thaw); use Scalar::Util qw/refaddr/; +use Carp; sub ref_ne { - my ($refa, $refb) = map { refaddr $_ or die "$_ is not a reference!" } @_[0,1]; + my ($refa, $refb) = map { refaddr $_ or croak "$_ is not a reference!" } @_[0,1]; cmp_ok ( $refa, '!=', @@ -55,23 +56,37 @@ my %stores = ( return $fire; }, - ($ENV{DBICTEST_MEMCACHED}) - ? do { - require Cache::Memcached; - my $memcached = Cache::Memcached->new( - { servers => [ $ENV{DBICTEST_MEMCACHED} ] } ); - - my $key = 'tmp_dbic_84serialize_memcached_test'; - - ( memcached => sub { - $memcached->set( $key, $_[0], 60 ); - local $DBIx::Class::ResultSourceHandle::thaw_schema = $schema; - return $memcached->get($key); - }); - } : () - , ); +if ($ENV{DBICTEST_MEMCACHED}) { + if (DBIx::Class::Optional::Dependencies->req_ok_for ('test_memcached')) { + my $memcached = Cache::Memcached->new( + { servers => [ $ENV{DBICTEST_MEMCACHED} ] } + ); + + my $key = 'tmp_dbic_84serialize_memcached_test'; + + $stores{memcached} = sub { + $memcached->set( $key, $_[0], 60 ) + or die "Unable to insert into $ENV{DBICTEST_MEMCACHED} - is server running?"; + local $DBIx::Class::ResultSourceHandle::thaw_schema = $schema; + return $memcached->get($key); + }; + } + else { + SKIP: { + skip 'Memcached tests need ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_memcached'), 1; + } + } +} +else { + SKIP: { + skip 'Set $ENV{DBICTEST_MEMCACHED} to run the memcached serialization tests', 1; + } +} + + + for my $name (keys %stores) { my $store = $stores{$name}; @@ -123,17 +138,12 @@ for my $name (keys %stores) { # Test resultsource with cached rows - my $query_count; - $cd_rs = $cd_rs->search ({}, { cache => 1 }); - - my $orig_debug = $schema->storage->debug; - $schema->storage->debug(1); - $schema->storage->debugcb(sub { $query_count++ } ); + $schema->is_executed_querycount( sub { + $cd_rs = $cd_rs->search ({}, { cache => 1 }); - # this will hit the database once and prime the cache - my @cds = $cd_rs->all; + # this will hit the database once and prime the cache + my @cds = $cd_rs->all; - lives_ok { $copy = $store->($cd_rs); ref_ne($copy, $cd_rs, 'Cached resultset cloned'); is_deeply ( @@ -143,12 +153,7 @@ for my $name (keys %stores) { ); is ($copy->count, $cd_rs->count, 'Cached count identical'); - } "serialize cached resultset lives: $name"; - - is ($query_count, 1, 'Only one db query fired'); - - $schema->storage->debug($orig_debug); - $schema->storage->debugcb(undef); + }, 1, 'Only one db query fired'); } # test schema-less detached thaw