mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-17 00:47:44 +00:00
Merge pt-fke-logger-2.2.
This commit is contained in:
60
t/lib/Cxn.t
60
t/lib/Cxn.t
@@ -9,7 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 19;
|
||||
use Test::More;
|
||||
|
||||
use Sandbox;
|
||||
use OptionParser;
|
||||
@@ -251,9 +251,65 @@ is_deeply(
|
||||
@ARGV = ();
|
||||
$o->get_opts();
|
||||
|
||||
# #############################################################################
|
||||
# The parent of a forked Cxn should not disconnect the dbh in DESTORY
|
||||
# because the child still has access to it.
|
||||
# #############################################################################
|
||||
|
||||
my $sync_file = "/tmp/pt-cxn-sync.$PID";
|
||||
my $outfile = "/tmp/pt-cxn-outfile.$PID";
|
||||
|
||||
my $pid;
|
||||
{
|
||||
my $parent_cxn = make_cxn(
|
||||
dsn_string => 'h=127.1,P=12345,u=msandbox,p=msandbox',
|
||||
parent => 1,
|
||||
);
|
||||
$parent_cxn->connect();
|
||||
|
||||
$pid = fork();
|
||||
if ( defined($pid) && $pid == 0 ) {
|
||||
# I am the child.
|
||||
# Wait for the parent to leave this code block which will cause
|
||||
# the $parent_cxn to be destroyed.
|
||||
PerconaTest::wait_for_files($sync_file);
|
||||
$parent_cxn->{parent} = 0;
|
||||
eval {
|
||||
$parent_cxn->dbh->do("SELECT 123 INTO OUTFILE '$outfile'");
|
||||
$parent_cxn->dbh->disconnect();
|
||||
};
|
||||
warn $EVAL_ERROR if $EVAL_ERROR;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
# Let the child know that we (the parent) have left that ^ code block,
|
||||
# so our copy of $parent_cxn has been destroyed, but hopefully the child's
|
||||
# copy is still alive, i.e. has an active/not-disconnected dbh.
|
||||
diag(`touch $sync_file`);
|
||||
|
||||
# Wait for the child.
|
||||
waitpid($pid, 0);
|
||||
|
||||
ok(
|
||||
-f $outfile,
|
||||
"Child created outfile"
|
||||
);
|
||||
|
||||
my $output = `cat $outfile 2>/dev/null`;
|
||||
|
||||
is(
|
||||
$output,
|
||||
"123\n",
|
||||
"Child executed query"
|
||||
);
|
||||
|
||||
unlink $sync_file if -f $sync_file;
|
||||
unlink $outfile if -f $outfile;
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$master_dbh->disconnect() if $master_dbh;
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
exit;
|
||||
done_testing;
|
||||
|
Reference in New Issue
Block a user