Skip to content

Commit b0e813c

Browse files
authored
Merge pull request #42 from charsbar/clear_handle_cache_if_dbh_set_to_undef
Clear %Handle cache if dbh is set to undef
2 parents 85291cb + d317d5e commit b0e813c

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Install dependencies
3434
run: curl -sL https://git.io/cpm | sudo perl - install -g --with-recommends --with-test --with-configure --show-build-log-on-failure --feature=test_mysql --feature=test_fork
3535
- name: Run tests
36-
run: DOD_TEST_DRIVER=MySQL prove -lr -j4 t
36+
run: DOD_TEST_DRIVER=MySQL prove -lr t
3737

3838
mariadb:
3939
runs-on: ubuntu-latest
@@ -45,7 +45,7 @@ jobs:
4545
- name: setup mariadb repo
4646
run: curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
4747
- name: apt-get
48-
run: sudo apt-get update && sudo apt-get install -y libmariadb-dev mariadb-server
48+
run: sudo apt-get update && sudo apt-get install -y libmariadb-dev libmariadb-dev-compat mariadb-server
4949
- name: Install dependencies
5050
run: curl -sL https://git.io/cpm | sudo perl - install -g --with-recommends --with-test --with-configure --show-build-log-on-failure --feature=test_mariadb --feature=test_fork
5151
- name: Run tests

lib/Data/ObjectDriver/Driver/DBI.pm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sub _is_fork_safe {
2323
return 1;
2424
}
2525

26-
__PACKAGE__->mk_accessors(qw( dsn username password connect_options dbh get_dbh dbd prefix reuse_dbh force_no_prepared_cache));
26+
__PACKAGE__->mk_accessors(qw( dsn username password connect_options get_dbh dbd prefix reuse_dbh force_no_prepared_cache));
2727

2828

2929
sub init {
@@ -52,7 +52,7 @@ sub init {
5252
weaken(my $driver_weaken = $driver);
5353
POSIX::AtFork->add_to_child(sub {
5454
return unless $driver_weaken;
55-
$driver_weaken->dbh(undef);
55+
$driver_weaken->{dbh} = undef;
5656
%Handles = ();
5757
});
5858
}
@@ -108,6 +108,18 @@ sub init_db {
108108
return $dbh;
109109
}
110110

111+
sub dbh {
112+
my $driver = shift;
113+
if (@_) {
114+
my $dbh = $driver->{dbh} = shift;
115+
if (!$dbh && $driver->reuse_dbh) {
116+
$dbh = delete $Handles{$driver->dsn};
117+
$dbh->disconnect if $dbh;
118+
}
119+
}
120+
$driver->{dbh};
121+
}
122+
111123
sub rw_handle {
112124
my $driver = shift;
113125
my $db = shift || 'main';

t/lib/DodTestUtil.pm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,42 @@ sub dsn {
6262
if ( $driver =~ /MySQL|MariaDB/ ) {
6363
if ( $driver eq 'MariaDB' && !$test_mysqld_dsn ) {
6464
my $help = `mysql --help`;
65-
my ($mariadb_version) = $help =~ /\A.*?([0-9]+\.[0-9]+)\.[0-9]+\-MariaDB/;
65+
my ($mariadb_major_version, $mariadb_minor_version) = $help =~ /\A.*?([0-9]+)\.([0-9]+)\.[0-9]+\-MariaDB/;
6666
no warnings 'redefine';
6767
$test_mysqld_dsn = \&Test::mysqld::dsn;
6868
*Test::mysqld::dsn = sub {
6969
my $dsn = $test_mysqld_dsn->(@_);
7070
# cf. https://github.com/kazuho/p5-test-mysqld/issues/32
71-
$dsn =~ s/;user=root// if $mariadb_version && $mariadb_version > 10.3;
71+
$dsn =~ s/;user=root// if $mariadb_major_version && $mariadb_major_version >= 10 && $mariadb_minor_version > 3;
7272
$dsn;
7373
};
7474
}
75+
if ($driver eq 'MySQL') {
76+
*Test::mysqld::wait_for_stop = sub {
77+
my $self = shift;
78+
local $?; # waitpid may change this value :/
79+
my $ct = 0;
80+
# XXX: modified
81+
while (waitpid($self->pid, POSIX::WNOHANG()) <= 0) {
82+
sleep 1;
83+
if ($ct++ > 10) {
84+
kill 9, $self->pid;
85+
}
86+
}
87+
$self->pid(undef);
88+
# might remain for example when sending SIGKILL
89+
unlink $self->my_cnf->{'pid-file'};
90+
};
91+
}
7592
$TestDB{$dbname} ||= Test::mysqld->new(
7693
my_cnf => {
7794
'skip-networking' => '', # no TCP socket
95+
'skip-name-resolve' => '',
96+
'default_authentication_plugin' => 'mysql_native_password',
7897
'sql-mode' => 'TRADITIONAL,NO_AUTO_VALUE_ON_ZERO,ONLY_FULL_GROUP_BY',
98+
'bind-address' => '127.0.0.1',
99+
'disable-log-bin' => '',
100+
'performance_schema' => 'OFF',
79101
}
80102
) or die $Test::mysqld::errstr;
81103
my $dsn = $TestDB{$dbname}->dsn;

0 commit comments

Comments
 (0)