X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F50fork.t;h=8fea72f51e731450e7e276a26c393c62d73684b5;hb=7d216b101775c472b012b257d848f50d78b193c8;hp=8379547a2d6b31fcd129ea5e4f943cf6fb16d8b5;hpb=649bfb8c11af342bcf7880ba52a7060a69c54068;p=dbsrgits%2FDBIx-Class.git diff --git a/t/50fork.t b/t/50fork.t index 8379547..8fea72f 100644 --- a/t/50fork.t +++ b/t/50fork.t @@ -18,7 +18,7 @@ if($num_children !~ /^[0-9]+$/ || $num_children < 10) { $num_children = 10; } -plan tests => $num_children + 6; +plan tests => ($num_children*2) + 6; use lib qw(t/lib); @@ -34,7 +34,7 @@ eval { { local $SIG{__WARN__} = sub {}; eval { $dbh->do("DROP TABLE cd") }; - $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(255) NOT NULL UNIQUE, year VARCHAR(255));"); + $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER, single_track INTEGER);"); } $schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 }); @@ -76,18 +76,36 @@ while(@pids < $num_children) { $pid = $$; - my $child_rs = $schema->resultset('CD')->search({ year => 1901 }); - my $row = $parent_rs->next; - if($row && $row->get_column('artist') =~ /^(?:123|456)$/) { - $schema->resultset('CD')->create({ title => "test success $pid", artist => $pid, year => scalar(@pids) }); + my $work = sub { + my $child_rs = $schema->resultset('CD')->search({ year => 1901 }); + my $row = $parent_rs->next; + $schema->resultset('CD')->create({ title => "test success $pid", artist => $pid, year => scalar(@pids) }) + if($row && $row->get_column('artist') =~ /^(?:123|456)$/); + }; + + # try with and without transactions + if ((@pids % 3) == 1) { + my $guard = $schema->txn_scope_guard; + $work->(); + $guard->commit; } + elsif ((@pids % 3) == 2) { + $schema->txn_do ($work); + } + else { + $work->(); + } + sleep(3); - exit; + exit 0; } ok(1, "past forking"); -waitpid($_,0) for(@pids); +for (@pids) { + waitpid($_,0); + ok (! $?, "Child $_ exitted cleanly"); +}; ok(1, "past waiting");