X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Ftxn.t;h=0edca6c440fd4e4319f0aa5e902c03b751e1b07e;hb=12e7015aa9372aeaf1aaa7e125b8ac8da216deb5;hp=41df4d565f44b76a32e554feeebe348243ea599a;hpb=8bab2062c234a0ebab1c177220ef1d13b281d5b2;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/txn.t b/t/storage/txn.t index 41df4d5..0edca6c 100644 --- a/t/storage/txn.t +++ b/t/storage/txn.t @@ -1,14 +1,16 @@ +# Test is sufficiently involved to *want* to run with "maximum paranoia" +BEGIN { $ENV{DBICTEST_OLD_MRO_SANITY_CHECK_ASSERTIONS} = 1 } + +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + 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; -use lib qw(t/lib); +use Errno (); + use DBICTest; my $code = sub { @@ -30,16 +32,17 @@ 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 for my $want (0,1) { my $schema = DBICTest->init_schema; - is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0'); + is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0'); my @titles = map {'txn_do test CD ' . $_} (1..5); my $artist = $schema->resultset('Artist')->find(1); @@ -59,7 +62,7 @@ for my $want (0,1) { title => "txn_do test CD $_", })->first->year, 2006, "new CD $_ year correct") for (1..5); - is( $schema->storage->{transaction_depth}, 0, 'txn depth has been reset'); + is( $schema->storage->transaction_depth, 0, 'txn depth has been reset'); } # Test txn_do() @_ aliasing support @@ -75,7 +78,7 @@ for my $want (0,1) { { my $schema = DBICTest->init_schema; - is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0'); + is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0'); my $nested_code = sub { my ($schema, $artist, $code) = @_; @@ -99,7 +102,7 @@ for my $want (0,1) { })->first->year, 2006, qq{nested txn_do CD$_ year ok}) for (1..10); is($artist->cds->count, $count_before+10, 'nested txn_do added all CDs'); - is( $schema->storage->{transaction_depth}, 0, 'txn depth has been reset'); + is( $schema->storage->transaction_depth, 0, 'txn depth has been reset'); } # test nested txn_begin on fresh connection @@ -110,6 +113,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 +136,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; @@ -205,12 +214,16 @@ sub _test_forking_action { SKIP: for my $count (1 .. 5) { - skip 'Weird DBI General Protection Faults, skip forking tests (RT#63104)', 5 + skip 'FIXME: Weird DBI General Protection Faults, skip forking tests (RT#63104)', 5 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; @@ -263,7 +276,7 @@ my $fail_code = sub { # Test failed txn_do() for my $pass (1,2) { - is( $schema->storage->{transaction_depth}, 0, "txn depth starts at 0 (pass $pass)"); + is( $schema->storage->transaction_depth, 0, "txn depth starts at 0 (pass $pass)"); my $artist = $schema->resultset('Artist')->find(3); @@ -277,13 +290,13 @@ my $fail_code = sub { })->first; ok(!defined($cd), qq{failed txn_do didn't change the cds table (pass $pass)}); - is( $schema->storage->{transaction_depth}, 0, "txn depth has been reset (pass $pass)"); + is( $schema->storage->transaction_depth, 0, "txn depth has been reset (pass $pass)"); } # Test failed txn_do() with failed rollback { - is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0'); + is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0'); my $artist = $schema->resultset('Artist')->find(3); @@ -325,7 +338,7 @@ my $fail_code = sub { { my $schema = DBICTest->init_schema(); - is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0'); + is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0'); my $nested_fail_code = sub { my ($schema, $artist, $code1, $code2) = @_; @@ -410,4 +423,52 @@ 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: DBIx::Class::Storage::DBI::txn_rollback(): 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'; + + # try the same broken exception object, but have exception_action inject it + $s->exception_action(sub { die $broken_exception }); + eval { + $s->txn_do( sub { + die "some string masked away"; + }); + }; + isa_ok $@, 'DBICTest::BrokenOverload', 'Deficient exception properly propagated'; + + is @w, 2, 'The warning was emitted a second time'; +} + done_testing;