1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
9 if( DBICTest::RunMode->is_plain ) {
10 print "1..0 # SKIP not running dangerous segfault-prone test on plain install\n";
16 use DBIx::Class::_Util 'scope_guard';
17 use DBIx::Class::Schema;
19 # Do not use T::B - the test is hard enough not to segfault as it is
22 # start with one failure, and decrement it at the end
26 printf STDOUT ("%s %u - %s\n",
27 ( $_[0] ? 'ok' : 'not ok' ),
34 printf STDERR ("# Failed test #%d at %s line %d\n",
43 # yes, make it even dirtier
44 my $schema = 'DBIx::Class::Schema';
46 $schema->connection('dbi:SQLite::memory:');
48 # this is incredibly horrible...
49 # demonstrate utter breakage of the reconnection/retry logic
51 open(my $stderr_copy, '>&', *STDERR) or die "Unable to dup STDERR: $!";
52 my $tf = File::Temp->new( UNLINK => 1 );
58 my $guard = scope_guard {
60 open(STDERR, '>&', $stderr_copy);
61 $output = do { local (@ARGV, $/) = $tf; <> };
69 open(STDERR, '>&', $tf) or die "Unable to reopen STDERR: $!";
71 $schema->storage->ensure_connected;
72 $schema->storage->_dbh->disconnect;
74 local $SIG{__WARN__} = sub {};
76 $schema->exception_action(sub {
77 ok(1, 'exception_action invoked');
78 # essentially what Dancer2's redirect() does after https://github.com/PerlDancer/Dancer2/pull/485
79 # which "nicely" combines with: https://metacpan.org/source/MARKOV/Log-Report-1.12/lib/Dancer2/Plugin/LogReport.pm#L143
80 # as encouraged by: https://metacpan.org/pod/release/MARKOV/Log-Report-1.12/lib/Dancer2/Plugin/LogReport.pod#Logging-DBIC-database-queries-and-errors
84 # this *DOES* throw, but the exception will *NEVER SHOW UP*
85 $schema->storage->dbh_do(sub { $_[1]->selectall_arrayref("SELECT * FROM wfwqfdqefqef") } );
91 ok(1, "Post-escape reached");
94 !!( $output =~ /DBIx::Class INTERNAL PANIC.+FIX YOUR ERROR HANDLING/s ),
95 'Proper warning emitted on STDERR'
96 ) or print STDERR "Instead found:\n\n$output\n";
98 print "1..$test_count\n";
100 # this is our "done_testing"
103 # avoid tasty segfaults on 5.8.x