Run the entire test suite under replicated SQLite on DBICTEST_VIA_REPLICATED
[dbsrgits/DBIx-Class.git] / t / storage / savepoints.t
index fab7036..3da77f1 100644 (file)
@@ -3,17 +3,31 @@ use warnings;
 
 use Test::More;
 use Test::Exception;
-use DBIx::Class::Optional::Dependencies ();
+use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer);
+
+use lib qw(t/lib);
+use DBICTest;
+
+{
+  package # moar hide
+    DBICTest::SVPTracerObj;
+
+  use base 'DBIx::Class::Storage::Statistics';
+
+  sub query_start { 'do notning'}
+  sub callback { 'dummy '}
+
+  for my $svpcall (map { "svp_$_" } qw(begin rollback release)) {
+    no strict 'refs';
+    *$svpcall = sub { $_[0]{uc $svpcall}++ };
+  }
+}
 
 my $env2optdep = {
   DBICTEST_PG => 'test_rdbms_pg',
   DBICTEST_MYSQL => 'test_rdbms_mysql',
 };
 
-use lib qw(t/lib);
-use DBICTest;
-use DBICTest::Stats;
-
 my $schema;
 
 for ('', keys %$env2optdep) { SKIP: {
@@ -56,9 +70,17 @@ for ('', keys %$env2optdep) { SKIP: {
 
   note "Testing $prefix";
 
-  my $stats = DBICTest::Stats->new;
-  $schema->storage->debugobj($stats);
-  $schema->storage->debug(1);
+  # can not use local() due to an unknown number of storages
+  # (think replicated)
+  my $orig_states = { map
+    { $_ => $schema->storage->$_ }
+    qw(debugcb debugobj debug)
+  };
+  my $sg = Scope::Guard->new(sub {
+    $schema->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
+  });
+  $schema->storage->debugobj (my $stats = DBICTest::SVPTracerObj->new);
+  $schema->storage->debug (1);
 
   $schema->resultset('Artist')->create({ name => 'foo' });
 
@@ -206,6 +228,15 @@ for ('', keys %$env2optdep) { SKIP: {
 
   is_deeply( $schema->storage->savepoints, [], 'All savepoints forgotten' );
 
+SKIP: {
+  skip "Reading inexplicably fails on very old replicated DBD::SQLite<1.33", 1 if (
+    $ENV{DBICTEST_VIA_REPLICATED}
+      and
+    $prefix eq 'SQLite Internal DB'
+      and
+    ! modver_gt_or_eq('DBD::SQLite', '1.33')
+  );
+
   ok($ars->search({ name => 'in_outer_transaction' })->first,
     'commit from outer transaction');
   ok($ars->search({ name => 'in_outer_transaction2' })->first,
@@ -215,14 +246,17 @@ for ('', keys %$env2optdep) { SKIP: {
   is $ars->search({ name => 'in_inner_transaction_rolling_back' })->first,
     undef,
     'rollback from inner transaction';
+}
 
 ### cleanupz
-  $schema->storage->dbh->do ("DROP TABLE artist");
+  $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
 }}
 
 done_testing;
 
 END {
-  eval { $schema->storage->dbh->do ("DROP TABLE artist") } if defined $schema;
+  local $SIG{__WARN__} = sigwarn_silencer( qr/Internal transaction state of handle/ )
+    unless modver_gt_or_eq('DBD::SQLite', '1.33');
+  eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") }) } if defined $schema;
   undef $schema;
 }