X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Ftxn.t;h=3ce4162b8a5d6f832e260926554f95937a552db2;hb=c5d7250ed959c707f2179ae5e10e8edb27adc92e;hp=41df4d565f44b76a32e554feeebe348243ea599a;hpb=8bab2062c234a0ebab1c177220ef1d13b281d5b2;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/txn.t b/t/storage/txn.t index 41df4d5..3ce4162 100644 --- a/t/storage/txn.t +++ b/t/storage/txn.t @@ -1,10 +1,6 @@ use strict; use warnings; -BEGIN { - require threads if $^O eq 'MSWin32'; # preload due to fork errors -} - use Test::More; use Test::Warn; use Test::Exception; @@ -30,9 +26,10 @@ my $code = sub { (ref $schema)->txn_do(sub{}); }, qr/storage/, "can't call txn_do without storage"); - throws_ok ( sub { + throws_ok { $schema->txn_do(''); - }, qr/must be a CODE reference/, '$coderef parameter check ok'); + } qr/\Qrun() requires a coderef to execute as its first argument/, + '$coderef parameter check ok'; } # Test successful txn_do() - scalar/list context @@ -110,6 +107,7 @@ for my $want (0,1) { is ($schema->storage->transaction_depth, 0, 'Start outside txn'); my @pids; + SKIP: for my $action ( sub { my $s = shift; @@ -132,8 +130,13 @@ for my $want (0,1) { }, ) { my $pid = fork(); - die "Unable to fork: $!\n" - if ! defined $pid; + + if( ! defined $pid ) { + skip "EAGAIN encountered, your system is likely bogged down: skipping forking test", 1 + if $! == Errno::EAGAIN(); + + die "Unable to fork: $!" + } if ($pid) { push @pids, $pid; @@ -209,8 +212,13 @@ sub _test_forking_action { if $^O eq 'MSWin32'; my $pid = fork(); - die "Unable to fork: $!\n" - if ! defined $pid; + if( ! defined $pid ) { + + skip "EAGAIN encountered, your system is likely bogged down: skipping forking test", 1 + if $! == Errno::EAGAIN(); + + die "Unable to fork: $!" + } if ($pid) { push @pids, $pid; @@ -410,4 +418,41 @@ warnings_are { } [], 'No warnings on AutoCommit => 0 with txn_do'; + +# make sure we are not fucking up the stacktrace on broken overloads +{ + package DBICTest::BrokenOverload; + + use overload '""' => sub { $_[0] }; +} + +{ + my @w; + local $SIG{__WARN__} = sub { + $_[0] =~ /\QExternal exception class DBICTest::BrokenOverload implements partial (broken) overloading preventing its instances from being used in simple (\E\$x eq \$y\Q) comparisons/ + ? push @w, @_ + : warn @_ + }; + + my $s = DBICTest->init_schema(no_deploy => 1); + $s->stacktrace(0); + my $g = $s->storage->txn_scope_guard; + my $broken_exception = bless {}, 'DBICTest::BrokenOverload'; + + # FIXME - investigate what confuses the regex engine below + + # do not reformat - line-num part of the test + my $ln = __LINE__ + 6; + throws_ok { + $s->txn_do( sub { + $s->txn_do( sub { + $s->storage->_dbh->disconnect; + die $broken_exception + }); + }) + } qr/\QTransaction aborted: $broken_exception. Rollback failed: lost connection to storage at @{[__FILE__]} line $ln\E\n/; # FIXME wtf - ...\E$/m doesn't work here + + is @w, 1, 'One matching warning only'; +} + done_testing;