Cleanup/improve the leaktest a bit
[dbsrgits/DBIx-Class.git] / t / storage / txn.t
index 895eaaa..f84fa9a 100644 (file)
@@ -233,6 +233,12 @@ sub _test_forking_action {
   for my $pid (@pids) {
     waitpid ($pid, 0);
     ok (! $?, "Child $pid exit ok (pass $pass)");
+  }
+
+  # it is important to reap all children before checking the final db-state
+  # otherwise a deadlock may occur between the transactions running in the
+  # children and the query of the parent
+  for my $pid (@pids) {
     isa_ok ($schema->resultset ('Artist')->find ({ name => "forking action $pid" }), 'DBIx::Class::Row');
   }
 }
@@ -357,9 +363,10 @@ my $fail_code = sub {
 
 # make sure AutoCommit => 0 on external handles behaves correctly with scope_guard
 warnings_are {
-  my $factory = DBICTest->init_schema (AutoCommit => 0);
+  my $factory = DBICTest->init_schema;
   cmp_ok ($factory->resultset('CD')->count, '>', 0, 'Something to delete');
   my $dbh = $factory->storage->dbh;
+  $dbh->{AutoCommit} = 0;
 
   ok (!$dbh->{AutoCommit}, 'AutoCommit is off on $dbh');
   my $schema = DBICTest::Schema->connect (sub { $dbh });
@@ -379,14 +386,14 @@ warnings_are {
 
 # make sure AutoCommit => 0 on external handles behaves correctly with txn_do
 warnings_are {
-  my $factory = DBICTest->init_schema (AutoCommit => 0);
+  my $factory = DBICTest->init_schema;
   cmp_ok ($factory->resultset('CD')->count, '>', 0, 'Something to delete');
   my $dbh = $factory->storage->dbh;
+  $dbh->{AutoCommit} = 0;
 
   ok (!$dbh->{AutoCommit}, 'AutoCommit is off on $dbh');
   my $schema = DBICTest::Schema->connect (sub { $dbh });
 
-
   lives_ok ( sub {
     $schema->txn_do (sub { $schema->resultset ('CD')->delete });
   }, 'No attempt to start a atransaction with txn_do');