fix up txn_begin and the ping_count test
[dbsrgits/DBIx-Class.git] / t / 92storage_ping_count.t
1 use strict;
2 use warnings;  
3
4 # Stolen from 76joins.t (a good test for this purpose)
5
6 use Test::More;
7 use lib qw(t/lib);
8 use DBICTest;
9 use Data::Dumper;
10 use DBIC::SqlMakerTest;
11
12 plan tests => 1;
13
14 my $ping_count = 0;
15
16 my $schema = DBICTest->init_schema();
17
18 {
19   local $SIG{__WARN__} = sub {};
20   require DBIx::Class::Storage::DBI;
21
22   my $ping = \&DBIx::Class::Storage::DBI::_ping;
23
24   *DBIx::Class::Storage::DBI::_ping = sub {
25     $ping_count++;
26     goto &$ping;
27   };
28 }
29
30 # perform some operations and make sure they don't ping
31
32 $schema->resultset('CD')->create({
33   cdid => 6, artist => 3, title => 'mtfnpy', year => 2009
34 });
35
36 $schema->resultset('CD')->create({
37   cdid => 7, artist => 3, title => 'mtfnpy2', year => 2009
38 });
39
40 $schema->storage->_dbh->disconnect;
41
42 $schema->resultset('CD')->create({
43   cdid => 8, artist => 3, title => 'mtfnpy3', year => 2009
44 });
45
46 $schema->storage->_dbh->disconnect;
47
48 $schema->txn_do(sub {
49  $schema->resultset('CD')->create({
50    cdid => 9, artist => 3, title => 'mtfnpy4', year => 2009
51  });
52 });
53
54 is $ping_count, 0, 'no _ping() calls';