Some stylistic test changes in preparation for next commits
[dbsrgits/DBIx-Class.git] / t / storage / savepoints.t
index 613eb14..5866e6d 100644 (file)
@@ -42,7 +42,7 @@ for ('', keys %$env2optdep) { SKIP: {
     skip ("Testing with ${prefix}_DSN needs " . DBIx::Class::Optional::Dependencies->req_missing_for( $env2optdep->{$prefix} ), 1)
       unless  DBIx::Class::Optional::Dependencies->req_ok_for($env2optdep->{$prefix});
 
-    $schema = DBICTest->connect_schema ($dsn,$user,$pass,{ auto_savepoint => 1 });
+    $schema = DBICTest::Schema->connect ($dsn,$user,$pass,{ auto_savepoint => 1 });
 
     my $create_sql;
     $schema->storage->ensure_connected;
@@ -69,8 +69,17 @@ for ('', keys %$env2optdep) { SKIP: {
 
   note "Testing $prefix";
 
-  local $schema->storage->{debugobj} = my $stats = DBICTest::SVPTracerObj->new;
-  local $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' });
 
@@ -229,14 +238,12 @@ for ('', keys %$env2optdep) { SKIP: {
     'rollback from inner transaction';
 
 ### cleanupz
-  $schema->storage->dbh->do ("DROP TABLE artist");
+  $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
 }}
 
 done_testing;
 
-# XXX: The leak tests fail if this is END compiled before (and thus
-# executed after) the one in DBICTest::BaseSchema
 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;
 }