Fix pesky on_connect_* race condition abraxxa++ ilmari++
[dbsrgits/DBIx-Class.git] / t / storage / on_connect_do.t
index 31d39c6..115fadb 100644 (file)
@@ -3,12 +3,13 @@ use warnings;
 
 # !!! do not replace this with done_testing - tests reside in the callbacks
 # !!! number of calls is important
-use Test::More tests => 12;
+use Test::More tests => 13;
 # !!!
+use Test::Warn;
 use Test::Exception;
 
 use lib qw(t/lib);
-use base 'DBICTest';
+use DBICTest;
 require DBI;
 
 
@@ -33,8 +34,13 @@ is_deeply (
 $schema->storage->disconnect;
 
 ok $schema->connection(
-    sub { DBI->connect(DBICTest->_database) },
+    sub { DBI->connect(DBICTest->_database, undef, undef, { AutoCommit => 0 }) },
     {
+        # DO NOT REMOVE - this seems like an unrelated piece of info,
+        # but is in fact a test for a bug where setting an accessor-via-option
+        # would trigger an early connect *bypassing* the on_connect_* pieces
+        cursor_class => 'DBIx::Class::Storage::Cursor',
+
         on_connect_do       => [
             'CREATE TABLE TEST_empty (id INTEGER)',
             [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
@@ -45,6 +51,11 @@ ok $schema->connection(
     },
 ), 'connection()';
 
+warnings_exist {
+  $schema->storage->ensure_connected
+} qr/The 'RaiseError' of the externally supplied DBI handle is set to false/,
+'Warning on clobbered AutoCommit => 0 fired';
+
 is_deeply (
   $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
   [ [ 2 ], [ 3 ], [ 7 ] ],
@@ -71,6 +82,7 @@ $schema->storage->disconnect();
 ok $disconnected, 'on_disconnect_do() called after disconnect()';
 
 isa_ok($cb_args[0], 'DBIx::Class::Storage', 'first arg to on_connect_do hook');
+@cb_args = ();
 
 sub check_exists {
     my $storage = shift;