forked from yappo/p5-dbix-skinny
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'topic/invalidate_txn_manager'
- Loading branch information
Showing
4 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use strict; | ||
use Test::More; | ||
use t::Utils; | ||
use Mock::Basic; | ||
|
||
subtest 'use transaction, disconnect, reconnect and use transaction again' => sub { | ||
my %connect_info = ( | ||
dsn => 'dbi:SQLite::memory:', | ||
connect_options => {RaiseError => 1, AutoCommit => 1}, | ||
); | ||
my $model = Mock::Basic->new(\%connect_info); | ||
|
||
eval { | ||
$model->txn_begin(); | ||
$model->txn_rollback(); | ||
}; | ||
ok !$@, "regular txn begin, then rollback - should be clean" . ( $@ ? ", but got $@" : ''); | ||
|
||
ok $model->_attributes->{dbh}, "dbh should be defined"; | ||
ok $model->_attributes->{txn_manager}, "txn manager should be defined"; | ||
|
||
eval { | ||
$model->disconnect(); | ||
}; | ||
ok !$@, "regular disconnect - should be clean" . ( $@ ? ", but got $@" : ''); | ||
|
||
ok ! $model->_attributes->{dbh}, "dbh should be undefined"; | ||
if (! ok ! $model->_attributes->{txn_manager}, "txn manager should be undefined" ) { | ||
# What, txn_manager still exists?! | ||
# Emulate this: long time passes... txn_manager and its dbh is | ||
# still dangling... and mysql server disconnects | ||
my $tm = $model->_attributes->{txn_manager}; | ||
if (my $dbh = $tm->{dbh}) { | ||
$dbh->disconnect; | ||
} | ||
} | ||
|
||
eval { | ||
$model->connect(); | ||
}; | ||
ok !$@, "regular connect - should be clean" . ( $@ ? ", but got $@" : '' ); | ||
|
||
eval { | ||
$model->txn_begin(); | ||
$model->txn_rollback(); | ||
}; | ||
ok !$@, "regular txn (again) - should be clean" . ($@ ? ", but got $@" : ''); | ||
}; | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters