mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 05:58:16 +00:00
Merge 2.1 r364 (has lots of test fixes).
This commit is contained in:
@@ -9,7 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 37;
|
||||
use Test::More;
|
||||
|
||||
use DSNParser;
|
||||
use OptionParser;
|
||||
@@ -545,6 +545,9 @@ foreach my $password_comma ( @password_commas ) {
|
||||
# #############################################################################
|
||||
# Bug 984915: SQL calls after creating the dbh aren't checked
|
||||
# #############################################################################
|
||||
# Make sure to disconnect any lingering dbhs, since full_output will fork
|
||||
# and then die, which will cause rollback warnings for connected dbhs.
|
||||
$dbh->disconnect() if $dbh;
|
||||
|
||||
$dsn = $dp->parse('h=127.1,P=12345,u=msandbox,p=msandbox');
|
||||
my @opts = $dp->get_cxn_params($dsn);
|
||||
@@ -569,5 +572,4 @@ like(
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$dbh->disconnect() if $dbh;
|
||||
exit;
|
||||
done_testing;
|
||||
|
@@ -9,13 +9,13 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 22;
|
||||
use Test::More;
|
||||
use Time::HiRes qw(sleep);
|
||||
use File::Temp qw( tempfile );
|
||||
use Daemon;
|
||||
use OptionParser;
|
||||
use PerconaTest;
|
||||
|
||||
#plan skip_all => "Hm";
|
||||
use constant PTDEVDEBUG => $ENV{PTDEVDEBUG} || 0;
|
||||
|
||||
my $o = new OptionParser(file => "$trunk/t/lib/samples/daemonizes.pl");
|
||||
@@ -263,4 +263,5 @@ ok(
|
||||
# Done.
|
||||
# #############################################################################
|
||||
rm_tmp_files();
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -9,15 +9,13 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 108;
|
||||
|
||||
use PerconaTest;
|
||||
|
||||
use OptionParser;
|
||||
|
||||
use Test::More;
|
||||
use File::Spec;
|
||||
use File::Temp ();
|
||||
|
||||
use PerconaTest;
|
||||
use OptionParser;
|
||||
|
||||
BEGIN {
|
||||
use_ok "Diskstats";
|
||||
use_ok "DiskstatsGroupByAll";
|
||||
@@ -25,7 +23,7 @@ BEGIN {
|
||||
use_ok "DiskstatsGroupBySample";
|
||||
}
|
||||
|
||||
my $o = new OptionParser(description => 'Diskstats');
|
||||
my $o = new OptionParser(description => 'Diskstats');
|
||||
$o->get_specs("$trunk/bin/pt-diskstats");
|
||||
$o->get_opts();
|
||||
|
||||
@@ -476,6 +474,7 @@ is_deeply(
|
||||
$obj->clear_state();
|
||||
|
||||
}
|
||||
|
||||
# ############################################################################
|
||||
# The three subclasses
|
||||
# ############################################################################
|
||||
@@ -491,7 +490,8 @@ for my $test (
|
||||
{
|
||||
class => "DiskstatsGroupBySample",
|
||||
results_file_prefix => "sample",
|
||||
}) {
|
||||
},
|
||||
) {
|
||||
my $obj = $test->{class}->new(OptionParser => $o, show_inactive => 1);
|
||||
my $prefix = $test->{results_file_prefix};
|
||||
|
||||
@@ -502,9 +502,8 @@ for my $test (
|
||||
$obj->set_show_line_between_samples(0);
|
||||
|
||||
for my $filename ( map "diskstats-00$_.txt", 1..5 ) {
|
||||
my $file = File::Spec->catfile( "t", "pt-diskstats", "samples", $filename );
|
||||
my $file_with_trunk = File::Spec->catfile( $trunk, $file );
|
||||
|
||||
my $file = File::Spec->catfile(qw(t pt-diskstats samples), $filename);
|
||||
my $file_with_trunk = File::Spec->catfile($trunk, $file);
|
||||
my $expected = "t/pt-diskstats/expected/${prefix}_$filename";
|
||||
|
||||
ok(
|
||||
@@ -571,10 +570,10 @@ EOF
|
||||
qr/Time between samples should be > 0, is /,
|
||||
"$test->{class}, ->_calc_deltas fails if the time elapsed is negative"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# Done.
|
||||
# ###########################################################################
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 38;
|
||||
use Test::More;
|
||||
|
||||
use VersionParser;
|
||||
use DuplicateKeyFinder;
|
||||
@@ -786,4 +786,5 @@ like(
|
||||
qr/Complete test coverage/,
|
||||
'_d() works'
|
||||
);
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -11,6 +11,10 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
if ( !$ENV{SLOW_TESTS} ) {
|
||||
plan skip_all => "lib/MasterSlave.t is a top 5 slowest file; set SLOW_TESTS=1 to enable it.";
|
||||
}
|
||||
|
||||
use MasterSlave;
|
||||
use DSNParser;
|
||||
use VersionParser;
|
||||
@@ -734,8 +738,6 @@ $sb->wipe_clean($master_dbh);
|
||||
diag(`$trunk/sandbox/stop-sandbox 2903 2902 2901 2900`);
|
||||
diag(`/tmp/12346/use -e "set global read_only=1"`);
|
||||
diag(`/tmp/12347/use -e "set global read_only=1"`);
|
||||
$sb->wait_for_slaves();
|
||||
diag(`$trunk/sandbox/test-env reset`);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -444,7 +444,6 @@ SKIP: {
|
||||
|
||||
$d = new RowDiff(dbh => $master_dbh);
|
||||
|
||||
diag(`$trunk/sandbox/mk-test-env reset >/dev/null 2>&1`);
|
||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
||||
$sb->load_file('master', 't/lib/samples/issue_11.sql');
|
||||
PerconaTest::wait_until(
|
||||
|
@@ -576,7 +576,6 @@ $dst->{dbh} = $dst_dbh;
|
||||
# ###########################################################################
|
||||
make_plugins();
|
||||
$sb->load_file('master', 't/lib/samples/before-TableSyncGroupBy.sql');
|
||||
sleep 1;
|
||||
|
||||
sync_table(
|
||||
src => "test.test1",
|
||||
@@ -606,7 +605,6 @@ is_deeply(
|
||||
# #############################################################################
|
||||
make_plugins();
|
||||
$sb->load_file('master', 't/lib/samples/issue_96.sql');
|
||||
sleep 1;
|
||||
|
||||
# Make paranoid-sure that the tables differ.
|
||||
my $r1 = $src_dbh->selectall_arrayref('SELECT from_city FROM issue_96.t WHERE package_id=4');
|
||||
@@ -1051,7 +1049,9 @@ my $output = '';
|
||||
"Retries wait"
|
||||
);
|
||||
}
|
||||
diag(`$trunk/sandbox/test-env reset`);
|
||||
diag(`/tmp/12347/use -e "stop slave"`);
|
||||
diag(`/tmp/12346/use -e "start slave"`);
|
||||
diag(`/tmp/12347/use -e "start slave"`);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
@@ -23,7 +23,7 @@ p="$PT_TMPDIR/collect/2011_12_05"
|
||||
# Default collect, no extras like gdb, tcpdump, etc.
|
||||
collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
||||
|
||||
wait_for_files "$p-hostname" "$p-opentables2" "$p-variables" "$p-df"
|
||||
wait_for_files "$p-hostname" "$p-opentables2" "$p-variables" "$p-df" "$p-innodbstatus2"
|
||||
|
||||
# Even if this system doesn't have all the cmds, collect should still
|
||||
# have created some files for cmds that (hopefully) all systems have.
|
||||
@@ -68,6 +68,7 @@ cmd_ok \
|
||||
"Finds MySQL error log"
|
||||
|
||||
if [[ "$SANDBOX_VERSION" > "5.0" ]]; then
|
||||
wait_for_files "$p-log_error"
|
||||
cmd_ok \
|
||||
"grep -qE 'Memory status|Open streams|Begin safemalloc' $p-log_error" \
|
||||
"debug"
|
||||
|
@@ -85,6 +85,7 @@ is \
|
||||
"$cnf_file" \
|
||||
"/tmp/12345/my.sandbox.cnf" \
|
||||
"find_my_cnf_file gets the correct file"
|
||||
[ $? -ne 0 ] && diag "$p/mysqld-instances"
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt")
|
||||
is "$res" "/tmp/12345/my.sandbox.cnf" "ps-mysqld-001.txt"
|
||||
|
@@ -28,9 +28,6 @@ if ( !$master_dbh ) {
|
||||
elsif ( !$slave1_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave1';
|
||||
}
|
||||
else {
|
||||
plan tests => 29;
|
||||
}
|
||||
|
||||
my $output;
|
||||
my $rows;
|
||||
@@ -188,55 +185,57 @@ cmp_ok(
|
||||
# #############################################################################
|
||||
# Bug 903387: pt-archiver doesn't honor b=1 flag to create SQL_LOG_BIN statement
|
||||
# #############################################################################
|
||||
SKIP: {
|
||||
skip('LOAD DATA LOCAL INFILE is disabled', 3) if !$can_load_data;
|
||||
$sb->load_file('master', "t/pt-archiver/samples/bulk_regular_insert.sql");
|
||||
$sb->wait_for_slaves();
|
||||
|
||||
$sb->load_file('master', "t/pt-archiver/samples/bulk_regular_insert.sql");
|
||||
$sb->wait_for_slaves();
|
||||
my $original_rows = $slave1_dbh->selectall_arrayref("SELECT * FROM bri.t ORDER BY id");
|
||||
is_deeply(
|
||||
$original_rows,
|
||||
[
|
||||
[1, 'aa', '11:11:11'],
|
||||
[2, 'bb', '11:11:12'],
|
||||
[3, 'cc', '11:11:13'],
|
||||
[4, 'dd', '11:11:14'],
|
||||
[5, 'ee', '11:11:15'],
|
||||
[6, 'ff', '11:11:16'],
|
||||
[7, 'gg', '11:11:17'],
|
||||
[8, 'hh', '11:11:18'],
|
||||
[9, 'ii', '11:11:19'],
|
||||
[10,'jj', '11:11:10'],
|
||||
],
|
||||
"Bug 903387: slave has rows"
|
||||
);
|
||||
|
||||
my $original_rows = $slave1_dbh->selectall_arrayref("SELECT * FROM bri.t ORDER BY id");
|
||||
is_deeply(
|
||||
$original_rows,
|
||||
[
|
||||
[1, 'aa', '11:11:11'],
|
||||
[2, 'bb', '11:11:12'],
|
||||
[3, 'cc', '11:11:13'],
|
||||
[4, 'dd', '11:11:14'],
|
||||
[5, 'ee', '11:11:15'],
|
||||
[6, 'ff', '11:11:16'],
|
||||
[7, 'gg', '11:11:17'],
|
||||
[8, 'hh', '11:11:18'],
|
||||
[9, 'ii', '11:11:19'],
|
||||
[10,'jj', '11:11:10'],
|
||||
],
|
||||
"Bug 903387: slave has rows"
|
||||
);
|
||||
$output = output(
|
||||
sub { pt_archiver::main(
|
||||
'--source', "D=bri,t=t,F=$cnf,b=1",
|
||||
'--dest', "D=bri,t=t_arch",
|
||||
qw(--where 1=1 --replace --commit-each --bulk-insert --bulk-delete),
|
||||
qw(--limit 10)) },
|
||||
);
|
||||
|
||||
$output = output(
|
||||
sub { pt_archiver::main(
|
||||
'--source', "D=bri,t=t,F=$cnf,b=1",
|
||||
'--dest', "D=bri,t=t_arch",
|
||||
qw(--where 1=1 --replace --commit-each --bulk-insert --bulk-delete),
|
||||
qw(--limit 10)) },
|
||||
);
|
||||
|
||||
$rows = $master_dbh->selectall_arrayref("SELECT * FROM bri.t ORDER BY id");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[
|
||||
[10,'jj', '11:11:10'],
|
||||
],
|
||||
"Bug 903387: rows deleted on master"
|
||||
) or diag(Dumper($rows));
|
||||
|
||||
$rows = $slave1_dbh->selectall_arrayref("SELECT * FROM bri.t ORDER BY id");
|
||||
is_deeply(
|
||||
$rows,
|
||||
$original_rows,
|
||||
"Bug 903387: slave still has rows"
|
||||
) or diag(Dumper($rows));
|
||||
$rows = $master_dbh->selectall_arrayref("SELECT * FROM bri.t ORDER BY id");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[
|
||||
[10,'jj', '11:11:10'],
|
||||
],
|
||||
"Bug 903387: rows deleted on master"
|
||||
) or diag(Dumper($rows));
|
||||
|
||||
$rows = $slave1_dbh->selectall_arrayref("SELECT * FROM bri.t ORDER BY id");
|
||||
is_deeply(
|
||||
$rows,
|
||||
$original_rows,
|
||||
"Bug 903387: slave still has rows"
|
||||
) or diag(Dumper($rows));
|
||||
}
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
exit;
|
||||
|
||||
done_testing;
|
||||
|
@@ -22,9 +22,6 @@ my $dbh = $sb->get_dbh_for('master');
|
||||
if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 2;
|
||||
}
|
||||
|
||||
my $cnf = "/tmp/12345/my.sandbox.cnf";
|
||||
my $sample = "t/pt-duplicate-key-checker/samples/";
|
||||
@@ -46,9 +43,47 @@ ok(
|
||||
"Shorten, not remove, clustered dupes"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Error if InnoDB table has no PK or unique indexes
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1036804
|
||||
# #############################################################################
|
||||
$sb->load_file('master', "t/pt-duplicate-key-checker/samples/idb-no-uniques-bug-894140.sql");
|
||||
|
||||
# PTDEBUG was auto-vivifying $clustered_key:
|
||||
#
|
||||
# PTDEBUG && _d('clustered key:', $clustered_key->{name},
|
||||
# $clustered_key->{colnames});
|
||||
#
|
||||
# if ( $clustered_key
|
||||
# && $args{clustered}
|
||||
# && $args{tbl_info}->{engine}
|
||||
# && $args{tbl_info}->{engine} =~ m/InnoDB/i )
|
||||
# {
|
||||
# push @dupes, $self->remove_clustered_duplicates($clustered_key...
|
||||
#
|
||||
# sub remove_clustered_duplicates {
|
||||
# my ( $self, $ck, $keys, %args ) = @_;
|
||||
# die "I need a ck argument" unless $ck;
|
||||
# die "I need a keys argument" unless $keys;
|
||||
# my $ck_cols = $ck->{colnames};
|
||||
# my @dupes;
|
||||
# KEY:
|
||||
# for my $i ( 0 .. @$keys - 1 ) {
|
||||
# my $key = $keys->[$i]->{colnames};
|
||||
# if ( $key =~ m/$ck_cols$/ ) {
|
||||
|
||||
my $output = `PTDEBUG=1 $trunk/bin/pt-duplicate-key-checker F=$cnf -d bug_1036804 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Use of uninitialized value/,
|
||||
'PTDEBUG doesn\'t auto-vivify cluster key hashref (bug 1036804)'
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -0,0 +1,9 @@
|
||||
DROP DATABASE IF EXISTS bug_1036804;
|
||||
CREATE DATABASE bug_1036804;
|
||||
USE bug_1036804;
|
||||
CREATE TABLE `t` (
|
||||
`col1` int(11) DEFAULT NULL,
|
||||
`col2` int(11) DEFAULT NULL,
|
||||
KEY `col1` (`col1`),
|
||||
KEY `col2` (`col2`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
@@ -9,7 +9,11 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 4;
|
||||
use Test::More;
|
||||
|
||||
if ( !$ENV{SLOW_TESTS} ) {
|
||||
plan skip_all => "pt-fifo-split/pt-fifo-split. is a top 5 slowest file; set SLOW_TESTS=1 to enable it.";
|
||||
}
|
||||
|
||||
use PerconaTest;
|
||||
require "$trunk/bin/pt-fifo-split";
|
||||
@@ -59,4 +63,5 @@ unlink '/tmp/pt-script.pid';
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -9,15 +9,12 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Time::HiRes qw(sleep);
|
||||
use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
require "$trunk/bin/pt-heartbeat";
|
||||
|
||||
diag(`$trunk/sandbox/test-env reset`);
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
@@ -37,10 +34,12 @@ else {
|
||||
plan tests => 29;
|
||||
}
|
||||
|
||||
diag(`rm -rf /tmp/pt-heartbeat-sentinel >/dev/null 2>&1`);
|
||||
$sb->create_dbs($master_dbh, ['test']);
|
||||
$sb->wait_for_slaves();
|
||||
|
||||
my $output;
|
||||
my $pid_file = "/tmp/__mk-heartbeat-test.pid";
|
||||
my $pid_file = "/tmp/pt-heartbeat-test.$PID.pid";
|
||||
|
||||
# Multi-update mode is the new, hi-res mode that allows a single table to
|
||||
# be updated by multiple servers: a slave's master, its master's master, etc.
|
||||
@@ -54,8 +53,7 @@ my @ports = qw(12345 12346 12347);
|
||||
foreach my $port (@ports) {
|
||||
system("$trunk/bin/pt-heartbeat -h 127.1 -u msandbox -p msandbox -P $port --database test --table heartbeat --create-table --update --interval 0.5 --daemonize --pid $pid_file.$port >/dev/null");
|
||||
|
||||
sleep 0.2;
|
||||
|
||||
PerconaTest::wait_for_files("$pid_file.$port");
|
||||
ok(
|
||||
-f "$pid_file.$port",
|
||||
"--update on $port started"
|
||||
@@ -154,7 +152,7 @@ ok(
|
||||
# ############################################################################
|
||||
|
||||
# $rows already has slave2 heartbeat info.
|
||||
sleep 1.0;
|
||||
sleep 1;
|
||||
|
||||
my $rows2 = $slave2_dbh->selectall_hashref("select * from test.heartbeat", 'server_id');
|
||||
|
||||
|
131
t/pt-kill/kill.t
131
t/pt-kill/kill.t
@@ -35,13 +35,16 @@ else {
|
||||
my $output;
|
||||
my $cnf='/tmp/12345/my.sandbox.cnf';
|
||||
|
||||
# TODO: These tests need something to match, so we background
|
||||
# a SLEEP(4) query and match that, but this isn't ideal because
|
||||
# it's time-based. Better is to use a specific db and --match-db.
|
||||
my $sys_cmd = "/tmp/12345/use -h127.1 -P12345 -umsandbox -pmsandbox -e 'select sleep(4)' >/dev/null 2>&1 &";
|
||||
|
||||
# #############################################################################
|
||||
# Test that --kill kills the connection.
|
||||
# #############################################################################
|
||||
|
||||
# Shell out to a sleep(10) query and try to capture the query.
|
||||
# Backticks don't work here.
|
||||
system("/tmp/12345/use -h127.1 -P12345 -umsandbox -pmsandbox -e 'select sleep(4)' >/dev/null 2>&1 &");
|
||||
system($sys_cmd);
|
||||
sleep 0.5;
|
||||
my $rows = $dbh->selectall_hashref('show processlist', 'id');
|
||||
my $pid;
|
||||
@@ -52,12 +55,12 @@ values %$rows;
|
||||
ok(
|
||||
$pid,
|
||||
'Got proc id of sleeping query'
|
||||
);
|
||||
) or diag(Dumper($rows));
|
||||
|
||||
$output = output(
|
||||
sub { pt_kill::main('-F', $cnf, qw(--kill --print --run-time 1 --interval 1),
|
||||
"--match-info", 'select sleep\(4\)',
|
||||
)
|
||||
sub {
|
||||
pt_kill::main('-F', $cnf, qw(--kill --print --run-time 1 --interval 1),
|
||||
"--match-info", 'select sleep\(4\)')
|
||||
},
|
||||
);
|
||||
|
||||
@@ -90,6 +93,7 @@ $pid = 0; # reuse, reset
|
||||
map { $pid = $_->{id} }
|
||||
grep { $_->{info} && $_->{info} =~ m/select sleep\(5\)/ }
|
||||
values %$rows;
|
||||
|
||||
ok(
|
||||
$pid,
|
||||
'Got proc id of sleeping query'
|
||||
@@ -130,43 +134,58 @@ my $sql = OptionParser->read_para_after(
|
||||
"$trunk/bin/pt-kill", qr/MAGIC_create_log_table/);
|
||||
$sql =~ s/kill_log/`kill_test`.`log_table`/;
|
||||
|
||||
my $log_dsn = "h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test,t=log_table";
|
||||
|
||||
$dbh->do($sql);
|
||||
|
||||
{
|
||||
system("/tmp/12345/use -h127.1 -P12345 -umsandbox -pmsandbox -e 'select sleep(4)' >/dev/null&");
|
||||
system($sys_cmd);
|
||||
sleep 0.5;
|
||||
|
||||
local $EVAL_ERROR;
|
||||
eval {
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1),
|
||||
"--match-info", 'select sleep\(4\)',
|
||||
"--log-dsn", q!h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test,t=log_table!,
|
||||
"--log-dsn", $log_dsn,
|
||||
)
|
||||
};
|
||||
|
||||
is(
|
||||
$EVAL_ERROR,
|
||||
$EVAL_ERROR,
|
||||
'',
|
||||
"--log-dsn works if the table exists and --create-log-table wasn't passed in."
|
||||
) or diag $EVAL_ERROR;
|
||||
);
|
||||
|
||||
local $EVAL_ERROR;
|
||||
my $results = eval { $dbh->selectall_arrayref("SELECT * FROM `kill_test`.`log_table`", { Slice => {} } ) };
|
||||
|
||||
is(
|
||||
$EVAL_ERROR,
|
||||
'',
|
||||
"...and we can query the table"
|
||||
) or diag $EVAL_ERROR;
|
||||
|
||||
is @{$results}, 1, "...which contains one entry";
|
||||
use Data::Dumper;
|
||||
is(
|
||||
scalar @$results,
|
||||
1,
|
||||
"...which contains one entry"
|
||||
);
|
||||
|
||||
my $reason = $dbh->selectrow_array("SELECT reason FROM `kill_test`.`log_table` WHERE kill_id=1");
|
||||
is $reason,
|
||||
|
||||
is(
|
||||
$reason,
|
||||
'Query matches Info spec',
|
||||
'reason gets set to something sensible';
|
||||
'reason gets set to something sensible'
|
||||
);
|
||||
|
||||
TODO: {
|
||||
local $::TODO = "Time_ms currently isn't reported";
|
||||
local $TODO = "Time_ms currently isn't reported";
|
||||
my $time_ms = $dbh->selectrow_array("SELECT Time_ms FROM `kill_test`.`log_table` WHERE kill_id=1");
|
||||
ok $time_ms;
|
||||
ok(
|
||||
$time_ms,
|
||||
"TIME_MS"
|
||||
);
|
||||
}
|
||||
|
||||
my $result = shift @$results;
|
||||
@@ -181,66 +200,76 @@ $dbh->do($sql);
|
||||
my %trimmed_result;
|
||||
@trimmed_result{ keys %$against } = @{$result}{ keys %$against };
|
||||
$trimmed_result{host} =~ s/localhost:[0-9]+/localhost/;
|
||||
|
||||
is_deeply(
|
||||
\%trimmed_result,
|
||||
$against,
|
||||
"...and was populated as expected",
|
||||
) or diag(Dumper($result));
|
||||
|
||||
system("/tmp/12345/use -h127.1 -P12345 -umsandbox -pmsandbox -e 'select sleep(4)' >/dev/null&");
|
||||
system($sys_cmd);
|
||||
sleep 0.5;
|
||||
|
||||
local $EVAL_ERROR;
|
||||
eval {
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1 --create-log-table),
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1),
|
||||
"--create-log-table",
|
||||
"--match-info", 'select sleep\(4\)',
|
||||
"--log-dsn", q!h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test,t=log_table!,
|
||||
"--log-dsn", $log_dsn,
|
||||
)
|
||||
};
|
||||
|
||||
is(
|
||||
$EVAL_ERROR,
|
||||
$EVAL_ERROR,
|
||||
'',
|
||||
"--log-dsn works if the table exists and --create-log-table was passed in."
|
||||
"--log-dsn --create-log-table and the table exists"
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
$dbh->do("DROP TABLE `kill_test`.`log_table`");
|
||||
$dbh->do("DROP TABLE IF EXISTS `kill_test`.`log_table`");
|
||||
|
||||
system("/tmp/12345/use -h127.1 -P12345 -umsandbox -pmsandbox -e 'select sleep(4)' >/dev/null&");
|
||||
system($sys_cmd);
|
||||
sleep 0.5;
|
||||
|
||||
local $EVAL_ERROR;
|
||||
eval {
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1 --create-log-table),
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1),
|
||||
"--create-log-table",
|
||||
"--match-info", 'select sleep\(4\)',
|
||||
"--log-dsn", q!h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test,t=log_table!,
|
||||
"--log-dsn", $log_dsn,
|
||||
)
|
||||
};
|
||||
|
||||
is(
|
||||
$EVAL_ERROR,
|
||||
'',
|
||||
"--log-dsn works if the table doesn't exists and --create-log-table was passed in."
|
||||
$EVAL_ERROR,
|
||||
'',
|
||||
"--log-dsn --create-log-table and the table doesn't exists"
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
$dbh->do("DROP TABLE `kill_test`.`log_table`");
|
||||
$dbh->do("DROP TABLE IF EXISTS `kill_test`.`log_table`");
|
||||
|
||||
local $EVAL_ERROR;
|
||||
eval {
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1),
|
||||
"--match-info", 'select sleep\(4\)',
|
||||
"--log-dsn", q!h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test,t=log_table!,
|
||||
"--log-dsn", $log_dsn,
|
||||
)
|
||||
};
|
||||
like $EVAL_ERROR,
|
||||
|
||||
like(
|
||||
$EVAL_ERROR,
|
||||
qr/\Q--log-dsn table does not exist. Please create it or specify\E/,
|
||||
"By default, --log-dsn doesn't autogenerate a table";
|
||||
"By default, --log-dsn doesn't autogenerate a table"
|
||||
);
|
||||
}
|
||||
|
||||
for my $dsn (
|
||||
q!h=127.1,P=12345,u=msandbox,p=msandbox,t=log_table!,
|
||||
q!h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test!,
|
||||
q!h=127.1,P=12345,u=msandbox,p=msandbox!,
|
||||
q/h=127.1,P=12345,u=msandbox,p=msandbox,t=log_table/,
|
||||
q/h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test/,
|
||||
q/h=127.1,P=12345,u=msandbox,p=msandbox/,
|
||||
) {
|
||||
local $EVAL_ERROR;
|
||||
eval {
|
||||
@@ -249,26 +278,42 @@ for my $dsn (
|
||||
"--log-dsn", $dsn,
|
||||
)
|
||||
};
|
||||
like $EVAL_ERROR,
|
||||
|
||||
like(
|
||||
$EVAL_ERROR,
|
||||
qr/\Q--log-dsn does not specify a database (D) or a database-qualified table (t)\E/,
|
||||
"--log-dsn croaks if t= or D= are absent";
|
||||
"--log-dsn croaks if t= or D= are absent"
|
||||
);
|
||||
}
|
||||
|
||||
# Run it twice
|
||||
for (1,2) {
|
||||
system("/tmp/12345/use -h127.1 -P12345 -umsandbox -pmsandbox -e 'select sleep(4)' >/dev/null&");
|
||||
system($sys_cmd);
|
||||
sleep 0.5;
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1 --create-log-table),
|
||||
|
||||
pt_kill::main('-F', $cnf, qw(--kill --run-time 1 --interval 1),
|
||||
"--create-log-table",
|
||||
"--match-info", 'select sleep\(4\)',
|
||||
"--log-dsn", q!h=127.1,P=12345,u=msandbox,p=msandbox,D=kill_test,t=log_table!,
|
||||
"--log-dsn", $log_dsn,
|
||||
);
|
||||
}
|
||||
|
||||
my $results = $dbh->selectall_arrayref("SELECT * FROM `kill_test`.`log_table`");
|
||||
|
||||
is @{$results}, 2, "Different --log-dsn runs reuse the same table.";
|
||||
is(
|
||||
scalar @$results,
|
||||
2,
|
||||
"Different --log-dsn runs reuse the same table."
|
||||
);
|
||||
|
||||
$dbh->do("DROP DATABASE kill_test");
|
||||
$dbh->do("DROP DATABASE IF EXISTS kill_test");
|
||||
|
||||
PerconaTest::wait_until(
|
||||
sub {
|
||||
$results = $dbh->selectall_hashref('SHOW PROCESSLIST', 'id');
|
||||
return !grep { ($_->{info} || '') =~ m/sleep \(4\)/ } values %$results;
|
||||
}
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
@@ -11,6 +11,10 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
if ( !$ENV{SLOW_TESTS} ) {
|
||||
plan skip_all => "pt-online-schema-change/privs.t is a top 5 slowest file; set SLOW_TESTS=1 to enable it.";
|
||||
}
|
||||
|
||||
use Data::Dumper;
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
|
@@ -21,8 +21,9 @@ use POSIX qw(mkfifo);
|
||||
# #########################################################################
|
||||
my $pid_file = '/tmp/mqd.pid';
|
||||
my $fifo = '/tmp/mqd.fifo';
|
||||
unlink $pid_file and diag("Unlinking existing $pid_file");
|
||||
unlink $fifo and diag("Unlinking existing $fifo");
|
||||
|
||||
unlink $pid_file if $pid_file;
|
||||
unlink $fifo if $fifo;
|
||||
|
||||
my ($start, $end, $waited, $timeout);
|
||||
SKIP: {
|
||||
@@ -40,7 +41,7 @@ SKIP: {
|
||||
);
|
||||
$end = time;
|
||||
$waited = $end - $start;
|
||||
if ( $timeout ) {
|
||||
if ( $timeout && -f $pid_file ) {
|
||||
# mqd ran longer than --read-timeout
|
||||
chomp(my $pid = slurp_file($pid_file));
|
||||
kill SIGTERM => $pid if $pid;
|
||||
@@ -52,7 +53,7 @@ SKIP: {
|
||||
);
|
||||
}
|
||||
|
||||
unlink $pid_file;
|
||||
unlink $pid_file if $pid_file;
|
||||
mkfifo $fifo, 0700;
|
||||
system("$trunk/t/pt-query-digest/samples/write-to-fifo.pl $fifo 4 &");
|
||||
|
||||
@@ -66,7 +67,7 @@ $timeout = wait_for(
|
||||
);
|
||||
$end = time;
|
||||
$waited = $end - $start;
|
||||
if ( $timeout ) {
|
||||
if ( $timeout && $pid_file ) {
|
||||
# mqd ran longer than --read-timeout
|
||||
chomp(my $pid = slurp_file($pid_file));
|
||||
kill SIGTERM => $pid if $pid;
|
||||
@@ -77,8 +78,8 @@ ok(
|
||||
sprintf("--read-timeout waited %.1f seconds reading a file", $waited)
|
||||
);
|
||||
|
||||
unlink $pid_file;
|
||||
unlink $fifo;
|
||||
unlink $pid_file if $pid_file;
|
||||
unlink $fifo if $fifo;
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
@@ -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,28 @@ 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 '`;
|
||||
# Check daemonization. This test used to print to STDOUT, causing
|
||||
# false-positive test errors. The output isn't needed. The tool
|
||||
# said "Reconnected to slave" every time it did SHOW SLAVE STATUS,
|
||||
# so needlessly. That was removed. Now it will print stuff when
|
||||
# we kill the process, which we don't want either.
|
||||
system("$cmd --delay 1m --interval 1s --run-time 5s --daemonize --pid $pid_file >/dev/null 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 +96,5 @@ like(
|
||||
# Done.
|
||||
# #############################################################################
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -13,23 +13,33 @@ use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
|
||||
require "$trunk/bin/pt-slave-find";
|
||||
|
||||
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 $slave_2_dbh = $sb->get_dbh_for('slave2');
|
||||
my $slave1_dbh = $sb->get_dbh_for('slave1');
|
||||
my $slave2_dbh = $sb->get_dbh_for('slave2');
|
||||
|
||||
diag(`$trunk/sandbox/test-env reset`);
|
||||
# This test is sensitive to ghost/old slaves created/destroyed by other
|
||||
# tests. So we stop the slaves, restart the master, and start everything
|
||||
# again. Hopefully this will return the env to its original state.
|
||||
$slave2_dbh->do("STOP SLAVE");
|
||||
$slave1_dbh->do("STOP SLAVE");
|
||||
diag(`/tmp/12345/stop >/dev/null`);
|
||||
diag(`/tmp/12345/start >/dev/null`);
|
||||
$slave1_dbh->do("START SLAVE");
|
||||
$slave2_dbh->do("START SLAVE");
|
||||
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
|
||||
if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
elsif ( !$slave_dbh ) {
|
||||
elsif ( !$slave1_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave';
|
||||
}
|
||||
elsif ( !$slave_2_dbh ) {
|
||||
elsif ( !$slave2_dbh ) {
|
||||
plan skip_all => 'Cannot connect to second sandbox slave';
|
||||
}
|
||||
else {
|
||||
@@ -42,7 +52,7 @@ my $output = `$trunk/bin/pt-slave-find --help`;
|
||||
like($output, qr/Prompt for a password/, 'It compiles');
|
||||
|
||||
# Double check that we're setup correctly.
|
||||
my $row = $slave_2_dbh->selectall_arrayref('SHOW SLAVE STATUS', {Slice => {}});
|
||||
my $row = $slave2_dbh->selectall_arrayref('SHOW SLAVE STATUS', {Slice => {}});
|
||||
is(
|
||||
$row->[0]->{master_port},
|
||||
'12346',
|
||||
@@ -108,8 +118,8 @@ my (@innodb_versions) = $result =~ /$innodb_re/g;
|
||||
$result =~ s/$innodb_re/InnoDB version BUILTIN/g;
|
||||
|
||||
my $master_version = VersionParser->new($master_dbh);
|
||||
my $slave_version = VersionParser->new($slave_dbh);
|
||||
my $slave2_version = VersionParser->new($slave_2_dbh);
|
||||
my $slave_version = VersionParser->new($slave1_dbh);
|
||||
my $slave2_version = VersionParser->new($slave2_dbh);
|
||||
|
||||
is(
|
||||
$innodb_versions[0],
|
||||
|
@@ -11,6 +11,11 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
if ( !$ENV{SLOW_TESTS} ) {
|
||||
plan skip_all => "pt-table-checksum/replication_filters.t is a top 5 slowest file; set SLOW_TESTS=1 to enable it.";
|
||||
}
|
||||
|
||||
|
||||
# Hostnames make testing less accurate. Tests need to see
|
||||
# that such-and-such happened on specific slave hosts, but
|
||||
# the sandbox servers are all on one host so all slaves have
|
||||
|
@@ -11,6 +11,10 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
if ( !$ENV{SLOW_TESTS} ) {
|
||||
plan skip_all => "pt-table-checksum/throttle.t is a top 5 slowest file; set SLOW_TESTS=1 to enable it.";
|
||||
}
|
||||
|
||||
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
|
||||
|
||||
use PerconaTest;
|
||||
|
Reference in New Issue
Block a user