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
|
||||
# that it reconnected and did some work, ending with "Setting slave
|
||||
# to run normally".
|
||||
diag('Running...');
|
||||
my $pid = fork();
|
||||
if ( $pid ) {
|
||||
# parent
|
||||
@@ -65,7 +64,6 @@ else {
|
||||
diag(`/tmp/12346/start >/dev/null`);
|
||||
# Ensure we don't break the sandbox -- instance 12347 will be disconnected
|
||||
# when its master gets rebooted
|
||||
diag("Restarting slave on instance 12347 after restarting instance 12346");
|
||||
diag(`/tmp/12347/use -e "stop slave; start slave"`);
|
||||
exit;
|
||||
}
|
||||
|
@@ -18,13 +18,17 @@ require "$trunk/bin/pt-slave-delay";
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
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 ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
elsif ( !$slave_dbh ) {
|
||||
plan skip_all => 'Cannot connect to second sandbox master';
|
||||
elsif ( !$slave1_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave1';
|
||||
}
|
||||
elsif ( !$slave2_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave2';
|
||||
}
|
||||
else {
|
||||
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.
|
||||
# #####1#######################################################################
|
||||
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/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/use -e "set global read_only=1"`);
|
||||
|
||||
$slave2_dbh->do('STOP SLAVE');
|
||||
$slave2_dbh->do('START SLAVE');
|
||||
|
||||
# #############################################################################
|
||||
# Check --use-master
|
||||
# #############################################################################
|
||||
@@ -85,11 +92,10 @@ like(
|
||||
);
|
||||
|
||||
# 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.
|
||||
$slave_dbh = $sb->get_dbh_for('slave2');
|
||||
$slave_dbh->do('STOP SLAVE');
|
||||
$slave_dbh->do('START SLAVE');
|
||||
$slave2_dbh->do('STOP SLAVE');
|
||||
$slave2_dbh->do('START SLAVE');
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More ;
|
||||
use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
@@ -24,31 +24,24 @@ if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
elsif ( !$slave_dbh ) {
|
||||
plan skip_all => 'Cannot connect to second sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 9;
|
||||
plan skip_all => 'Cannot connect to sandbox slave1';
|
||||
}
|
||||
|
||||
my $output;
|
||||
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
|
||||
system("$cmd --delay 1m --interval 1s --run-time 5s --daemonize --pid /tmp/mk-slave-delay.pid");
|
||||
$output = `ps -eaf | grep 'mk-slave-delay' | grep ' \-\-delay 1m '`;
|
||||
system("$cmd --delay 1m --interval 1s --run-time 5s --daemonize --pid $pid_file 2>&1");
|
||||
PerconaTest::wait_for_files($pid_file);
|
||||
chomp(my $pid = `cat $pid_file`);
|
||||
$output = `ps x | grep "^[ ]*$pid"`;
|
||||
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
|
||||
diag(`kill $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.
|
||||
@@ -99,4 +92,5 @@ like(
|
||||
# Done.
|
||||
# #############################################################################
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
Reference in New Issue
Block a user