mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 03:19:07 +00:00
Fix and stablize pt-slave-delay tests.
This commit is contained in:
@@ -46,7 +46,6 @@ my $output;
|
|||||||
# the child should restart the slave, and the tool should report
|
# the child should restart the slave, and the tool should report
|
||||||
# that it reconnected and did some work, ending with "Setting slave
|
# that it reconnected and did some work, ending with "Setting slave
|
||||||
# to run normally".
|
# to run normally".
|
||||||
diag('Running...');
|
|
||||||
my $pid = fork();
|
my $pid = fork();
|
||||||
if ( $pid ) {
|
if ( $pid ) {
|
||||||
# parent
|
# parent
|
||||||
@@ -65,7 +64,6 @@ else {
|
|||||||
diag(`/tmp/12346/start >/dev/null`);
|
diag(`/tmp/12346/start >/dev/null`);
|
||||||
# Ensure we don't break the sandbox -- instance 12347 will be disconnected
|
# Ensure we don't break the sandbox -- instance 12347 will be disconnected
|
||||||
# when its master gets rebooted
|
# when its master gets rebooted
|
||||||
diag("Restarting slave on instance 12347 after restarting instance 12346");
|
|
||||||
diag(`/tmp/12347/use -e "stop slave; start slave"`);
|
diag(`/tmp/12347/use -e "stop slave; start slave"`);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@@ -18,13 +18,17 @@ require "$trunk/bin/pt-slave-delay";
|
|||||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||||
my $master_dbh = $sb->get_dbh_for('master');
|
my $master_dbh = $sb->get_dbh_for('master');
|
||||||
my $slave_dbh = $sb->get_dbh_for('slave1');
|
my $slave1_dbh = $sb->get_dbh_for('slave1');
|
||||||
|
my $slave2_dbh = $sb->get_dbh_for('slave2');
|
||||||
|
|
||||||
if ( !$master_dbh ) {
|
if ( !$master_dbh ) {
|
||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
elsif ( !$slave_dbh ) {
|
elsif ( !$slave1_dbh ) {
|
||||||
plan skip_all => 'Cannot connect to second sandbox master';
|
plan skip_all => 'Cannot connect to sandbox slave1';
|
||||||
|
}
|
||||||
|
elsif ( !$slave2_dbh ) {
|
||||||
|
plan skip_all => 'Cannot connect to sandbox slave2';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 6;
|
plan tests => 6;
|
||||||
@@ -50,7 +54,7 @@ unlike($output, qr/Missing DSN part 'h'/, 'Does not require h DSN part');
|
|||||||
# just disable log-bin and log-slave-updates on the slave.
|
# just disable log-bin and log-slave-updates on the slave.
|
||||||
# #####1#######################################################################
|
# #####1#######################################################################
|
||||||
diag(`cp /tmp/12346/my.sandbox.cnf /tmp/12346/my.sandbox.cnf-original`);
|
diag(`cp /tmp/12346/my.sandbox.cnf /tmp/12346/my.sandbox.cnf-original`);
|
||||||
diag(`sed -i.bak -e '/log.bin\\|log.slave/d' /tmp/12346/my.sandbox.cnf`);
|
diag(`sed -i.bak -e '/log-bin/d' -e '/log_slave_updates/d' /tmp/12346/my.sandbox.cnf`);
|
||||||
diag(`/tmp/12346/stop >/dev/null`);
|
diag(`/tmp/12346/stop >/dev/null`);
|
||||||
diag(`/tmp/12346/start >/dev/null`);
|
diag(`/tmp/12346/start >/dev/null`);
|
||||||
|
|
||||||
@@ -66,6 +70,9 @@ diag(`mv /tmp/12346/my.sandbox.cnf-original /tmp/12346/my.sandbox.cnf`);
|
|||||||
diag(`/tmp/12346/start >/dev/null`);
|
diag(`/tmp/12346/start >/dev/null`);
|
||||||
diag(`/tmp/12346/use -e "set global read_only=1"`);
|
diag(`/tmp/12346/use -e "set global read_only=1"`);
|
||||||
|
|
||||||
|
$slave2_dbh->do('STOP SLAVE');
|
||||||
|
$slave2_dbh->do('START SLAVE');
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Check --use-master
|
# Check --use-master
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
@@ -85,11 +92,10 @@ like(
|
|||||||
);
|
);
|
||||||
|
|
||||||
# Sometimes the slave will be in a state of "reconnecting to master" that will
|
# Sometimes the slave will be in a state of "reconnecting to master" that will
|
||||||
# take a while. Help that along. But, we've disconnected $slave_dbh by doing
|
# take a while. Help that along. But, we've disconnected $slave1_dbh by doing
|
||||||
# 'stop' on the sandbox above, so we need to reconnect.
|
# 'stop' on the sandbox above, so we need to reconnect.
|
||||||
$slave_dbh = $sb->get_dbh_for('slave2');
|
$slave2_dbh->do('STOP SLAVE');
|
||||||
$slave_dbh->do('STOP SLAVE');
|
$slave2_dbh->do('START SLAVE');
|
||||||
$slave_dbh->do('START SLAVE');
|
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More ;
|
use Test::More;
|
||||||
|
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
use Sandbox;
|
use Sandbox;
|
||||||
@@ -24,31 +24,24 @@ if ( !$master_dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
elsif ( !$slave_dbh ) {
|
elsif ( !$slave_dbh ) {
|
||||||
plan skip_all => 'Cannot connect to second sandbox master';
|
plan skip_all => 'Cannot connect to sandbox slave1';
|
||||||
}
|
|
||||||
else {
|
|
||||||
plan tests => 9;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $output;
|
my $output;
|
||||||
my $cmd = "$trunk/bin/pt-slave-delay -F /tmp/12346/my.sandbox.cnf h=127.1";
|
my $cmd = "$trunk/bin/pt-slave-delay -F /tmp/12346/my.sandbox.cnf h=127.1";
|
||||||
|
my $pid_file = "/tmp/pt-slave-delay-test.$PID";
|
||||||
|
|
||||||
# Check daemonization
|
# Check daemonization
|
||||||
system("$cmd --delay 1m --interval 1s --run-time 5s --daemonize --pid /tmp/mk-slave-delay.pid");
|
system("$cmd --delay 1m --interval 1s --run-time 5s --daemonize --pid $pid_file 2>&1");
|
||||||
$output = `ps -eaf | grep 'mk-slave-delay' | grep ' \-\-delay 1m '`;
|
PerconaTest::wait_for_files($pid_file);
|
||||||
|
chomp(my $pid = `cat $pid_file`);
|
||||||
|
$output = `ps x | grep "^[ ]*$pid"`;
|
||||||
like($output, qr/$cmd/, 'It lives daemonized');
|
like($output, qr/$cmd/, 'It lives daemonized');
|
||||||
|
|
||||||
ok(-f '/tmp/mk-slave-delay.pid', 'PID file created');
|
|
||||||
my ($pid) = $output =~ /\s+(\d+)\s+/;
|
|
||||||
$output = `cat /tmp/mk-slave-delay.pid`;
|
|
||||||
# If this test fails, it may be because another instances of
|
|
||||||
# mk-slave-delay is running.
|
|
||||||
is($output, $pid, 'PID file has correct PID');
|
|
||||||
|
|
||||||
# Kill it
|
# Kill it
|
||||||
diag(`kill $pid`);
|
diag(`kill $pid`);
|
||||||
wait_until(sub{!kill 0, $pid});
|
wait_until(sub{!kill 0, $pid});
|
||||||
ok(! -f '/tmp/mk-slave-delay.pid', 'PID file removed');
|
ok(! -f $pid_file, 'PID file removed');
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Check that SLAVE-HOST can be given by cmd line opts.
|
# Check that SLAVE-HOST can be given by cmd line opts.
|
||||||
@@ -99,4 +92,5 @@ like(
|
|||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||||
|
done_testing;
|
||||||
exit;
|
exit;
|
||||||
|
Reference in New Issue
Block a user