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