Avoid infinite loop if save point does not exist
[dbsrgits/DBIx-Class.git] / t / storage / savepoints.t
index 0c56afc..eba3bce 100644 (file)
@@ -3,6 +3,9 @@ use warnings;
 
 use Test::More;
 use Test::Exception;
+use DBIx::Class::Optional::Dependencies;
+use DBIx::Class::_Util qw(sigwarn_silencer scope_guard);
+use Scalar::Util 'weaken';
 
 use lib qw(t/lib);
 use DBICTest;
@@ -228,6 +231,20 @@ for ('', keys %$env2optdep) { SKIP: {
     undef,
     'rollback from inner transaction';
 
+  # make sure a fresh txn will work after above
+  $schema->storage->txn_do(sub { ok "noop" } );
+
+### Make sure non-existend savepoint release doesn't infloop itself
+  {
+    weaken( my $s = $schema );
+
+    throws_ok {
+      $s->storage->txn_do(sub { $s->svp_release('wibble') })
+    } qr/Savepoint 'wibble' does not exist/,
+      "Calling svp_release on a non-existant savepoint throws expected error"
+    ;
+  }
+
 ### cleanupz
   $schema->storage->dbh->do ("DROP TABLE artist");
 }}
@@ -235,6 +252,6 @@ for ('', keys %$env2optdep) { SKIP: {
 done_testing;
 
 END {
-  eval { $schema->storage->dbh->do ("DROP TABLE artist") } if defined $schema;
+  eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") }) } if defined $schema;
   undef $schema;
 }