1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
10 use DBICTest::Util 'PEEPEENESS';
14 [ on_connect_do => "_NOPE_" ],
15 [ on_connect_call => sub { shift->_dbh->do("_NOPE_") } ],
16 [ on_connect_call => "_NOPE_" ],
18 for my $method (qw( ensure_connected _server_info _get_server_version _get_dbh )) {
20 my $s = DBICTest->init_schema(
22 on_disconnect_call => sub { fail 'Disconnector should not be invoked' },
26 my $storage = $s->storage;
27 $storage = $storage->master
28 if $storage->isa('DBIx::Class::Storage::DBI::Replicated');
30 ok( ! $storage->connected, 'Starting unconnected' );
32 my $desc = "calling $method with broken on_connect action @{[ explain $conn_args ]}";
34 throws_ok { $storage->$method }
36 "Throwing correctly when $desc";
38 ok( ! $storage->connected, "Still not connected after $desc" );
40 # this checks that the on_disconect_call FAIL won't trigger
46 [ on_disconnect_do => "_NOPE_" ],
47 [ on_disconnect_call => sub { shift->_dbh->do("_NOPE_") } ],
48 [ on_disconnect_call => "_NOPE_" ],
50 my $s = DBICTest->init_schema( no_deploy => 1, @$conn_args );
52 my $storage = $s->storage;
53 $storage = $storage->master
54 if $storage->isa('DBIx::Class::Storage::DBI::Replicated');
56 my $desc = "broken on_disconnect action @{[ explain $conn_args ]}";
59 my $dbh = $storage->dbh;
61 ok ($dbh->FETCH('Active'), 'Freshly connected DBI handle is healthy');
63 warnings_exist { eval { $storage->disconnect } } [
64 qr/\QDisconnect action failed\E .+ _NOPE_ \b/x
65 ], "Found warning of failed $desc";
67 ok (! $dbh->FETCH('Active'), "Actual DBI disconnect was not prevented by $desc" );
70 my $schema = DBICTest->init_schema;
75 $schema->resultset('CD')->create({ title => 'vacation in antarctica' })
77 qr/DBI Exception.+(?x:
78 \QNOT NULL constraint failed: cd.artist\E
80 \Qcd.artist may not be NULL\E
82 ); # as opposed to some other error
83 }, [], 'No warnings besides exception' );
85 my $dbh = $schema->storage->dbh;
89 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
91 qr/DBI Exception.+no such table.+nonexistent_table/s,
92 'DBI exceptions properly handled by dbic-installed callback'
95 # This usage is a bit unusual but it was actually seen in the wild
96 # destruction of everything except the $dbh should use the proper
100 skip "Your perl version $] appears to leak like a sieve - skipping garbage collected \$schema test", 1
106 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
108 qr/DBI Exception.+unhandled by DBIC.+no such table.+nonexistent_table/s,
109 'callback works after $schema is gone'