mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-10 01:12:18 +08:00
Fix and make tests more reliable.
This commit is contained in:
@@ -255,12 +255,17 @@ sub wait_for {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub wait_for_table {
|
sub wait_for_table {
|
||||||
my ($dbh, $tbl) = @_;
|
my ($dbh, $tbl, $where) = @_;
|
||||||
|
my $sql = "SELECT 1 FROM $tbl" . ($where ? " WHERE $where LIMIT 1" : "");
|
||||||
return wait_until(
|
return wait_until(
|
||||||
sub {
|
sub {
|
||||||
my $r;
|
my $r;
|
||||||
eval { $r = $dbh->selectrow_arrayref("SELECT 1 FROM $tbl"); };
|
eval { $r = $dbh->selectrow_arrayref($sql); };
|
||||||
return $EVAL_ERROR ? 0 : 1;
|
return 0 if $EVAL_ERROR;
|
||||||
|
if ( $where ) {
|
||||||
|
return 0 unless $r && @$r;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
},
|
},
|
||||||
0.25,
|
0.25,
|
||||||
15,
|
15,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -122,7 +122,8 @@ SKIP: {
|
|||||||
|
|
||||||
# Run it again without DSN b so changes should be made on slave.
|
# Run it again without DSN b so changes should be made on slave.
|
||||||
$sb->load_file('master', "t/pt-archiver/samples/delete_more.sql");
|
$sb->load_file('master', "t/pt-archiver/samples/delete_more.sql");
|
||||||
PerconaTest::wait_for_table($slave_dbh, "`dm`.`main_table-123`");
|
PerconaTest::wait_for_table($slave_dbh, "`dm`.`main_table-123`", 'id=5');
|
||||||
|
PerconaTest::wait_for_table($slave_dbh, "`dm`.`other_table-123`", 'id=r6');
|
||||||
|
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$slave_dbh->selectall_arrayref('select * from `main_table-123` order by id'),
|
$slave_dbh->selectall_arrayref('select * from `main_table-123` order by id'),
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ my $cmd = "$trunk/bin/pt-archiver";
|
|||||||
# Test the custom plugin gt_n.
|
# Test the custom plugin gt_n.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
$sb->load_file('master', 't/pt-archiver/samples/gt_n.sql');
|
$sb->load_file('master', 't/pt-archiver/samples/gt_n.sql');
|
||||||
PerconaTest::wait_for_table($dbh, 'gt_n.t1');
|
PerconaTest::wait_for_table($dbh, 'gt_n.t1', 'status="ok"');
|
||||||
my $sql = 'select status, count(*) from gt_n.t1 group by status';
|
my $sql = 'select status, count(*) from gt_n.t1 group by status';
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$dbh->selectall_arrayref($sql),
|
$dbh->selectall_arrayref($sql),
|
||||||
|
|||||||
@@ -32,42 +32,42 @@ SKIP: {
|
|||||||
|
|
||||||
# There's no hung queries so we'll just make sure it outputs anything,
|
# There's no hung queries so we'll just make sure it outputs anything,
|
||||||
# its debug stuff in this case.
|
# its debug stuff in this case.
|
||||||
`$cmd --print --interval 1s --run-time 2 --pid /tmp/mk-kill.pid --log /tmp/mk-kill.log --daemonize`;
|
`$cmd --print --interval 1s --run-time 2 --pid /tmp/pt-kill.pid --log /tmp/pt-kill.log --daemonize`;
|
||||||
$output = `ps -eaf | grep 'mk-kill \-F'`;
|
$output = `ps -eaf | grep 'pt-kill \-F'`;
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/mk-kill -F /,
|
qr/pt-kill -F /,
|
||||||
'It lives daemonized'
|
'It lives daemonized'
|
||||||
);
|
);
|
||||||
ok(
|
ok(
|
||||||
-f '/tmp/mk-kill.pid',
|
-f '/tmp/pt-kill.pid',
|
||||||
'PID file created'
|
'PID file created'
|
||||||
);
|
);
|
||||||
ok(
|
ok(
|
||||||
-f '/tmp/mk-kill.log',
|
-f '/tmp/pt-kill.log',
|
||||||
'Log file created'
|
'Log file created'
|
||||||
);
|
);
|
||||||
|
|
||||||
sleep 2;
|
sleep 2;
|
||||||
ok(
|
ok(
|
||||||
!-f '/tmp/mk-kill.pid',
|
!-f '/tmp/pt-kill.pid',
|
||||||
'PID file removed'
|
'PID file removed'
|
||||||
);
|
);
|
||||||
|
|
||||||
diag(`rm -rf /tmp/mk-kill.log`);
|
diag(`rm -rf /tmp/pt-kill.log`);
|
||||||
}
|
}
|
||||||
|
|
||||||
# #########################################################################
|
# #########################################################################
|
||||||
# Issue 391: Add --pid option to all scripts
|
# Issue 391: Add --pid option to all scripts
|
||||||
# #########################################################################
|
# #########################################################################
|
||||||
`touch /tmp/mk-script.pid`;
|
`touch /tmp/pt-script.pid`;
|
||||||
$output = `$cmd $trunk/t/lib/samples/pl/recset006.txt --match-state Locked --print --pid /tmp/mk-script.pid 2>&1`;
|
$output = `$cmd $trunk/t/lib/samples/pl/recset006.txt --match-state Locked --print --pid /tmp/pt-script.pid 2>&1`;
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr{PID file /tmp/mk-script.pid already exists},
|
qr{PID file /tmp/pt-script.pid already exists},
|
||||||
'Dies if PID file already exists (--pid without --daemonize) (issue 391)'
|
'Dies if PID file already exists (--pid without --daemonize) (issue 391)'
|
||||||
);
|
);
|
||||||
`rm -rf /tmp/mk-script.pid`;
|
`rm -rf /tmp/pt-script.pid`;
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ ok(
|
|||||||
'--report-format', 'query_report,profile',
|
'--report-format', 'query_report,profile',
|
||||||
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
|
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
|
||||||
"t/pt-query-digest/samples/slow007_explain_3.txt",
|
"t/pt-query-digest/samples/slow007_explain_3.txt",
|
||||||
trf => "sed 's/at [a-zA-Z\/\-]\\+ line [0-9]\\+/at line ?/'",
|
trf => "sed 's/at .* line [0-9]*/at line ?/'",
|
||||||
),
|
),
|
||||||
'Analysis for slow007 with --explain, failed',
|
'Analysis for slow007 with --explain, failed',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -52,18 +52,20 @@ $master_dbh->do('create table t (i int, unique index (i))');
|
|||||||
$master_dbh->do('insert into t values (1),(2)');
|
$master_dbh->do('insert into t values (1),(2)');
|
||||||
|
|
||||||
$slave_dbh->do('insert into t values (3)');
|
$slave_dbh->do('insert into t values (3)');
|
||||||
|
PerconaTest::wait_for_table($slave_dbh, 'test.t', 'i=1');
|
||||||
|
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$master_dbh->selectall_arrayref('select * from test.t'),
|
$master_dbh->selectall_arrayref('select * from test.t order by i'),
|
||||||
[[1],[2]],
|
[[1],[2]],
|
||||||
'Data on master before sync'
|
'Data on master before sync'
|
||||||
);
|
);
|
||||||
|
use Data::Dumper;
|
||||||
|
my $rows = $slave_dbh->selectall_arrayref('select * from test.t order by i');
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$slave_dbh->selectall_arrayref('select * from test.t'),
|
$rows,
|
||||||
[[1],[2],[3]],
|
[[1],[2],[3]],
|
||||||
'Data on slave before sync'
|
'Data on slave before sync'
|
||||||
);
|
) or print Dumper($rows);
|
||||||
|
|
||||||
$master_dbh->do('SET GLOBAL binlog_format="ROW"');
|
$master_dbh->do('SET GLOBAL binlog_format="ROW"');
|
||||||
$master_dbh->disconnect();
|
$master_dbh->disconnect();
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ output(
|
|||||||
|
|
||||||
my $binlog = $master_dbh->selectrow_arrayref('show master logs');
|
my $binlog = $master_dbh->selectrow_arrayref('show master logs');
|
||||||
|
|
||||||
$output = `$mysqlbinlog /tmp/12345/data/$binlog->[0] | grep maatkit`;
|
$output = `$mysqlbinlog /tmp/12345/data/$binlog->[0] | grep 'percona-toolkit'`;
|
||||||
$output =~ s/pid:\d+/pid:0/ if $output;
|
$output =~ s/pid:\d+/pid:0/ if $output;
|
||||||
$output =~ s/host:\S+?\*/host:-*/ if $output;
|
$output =~ s/host:\S+?\*/host:-*/ if $output;
|
||||||
is(
|
is(
|
||||||
$output,
|
$output,
|
||||||
"DELETE FROM `onlythisdb`.`t` WHERE `i`='5' LIMIT 1 /*maatkit src_db:onlythisdb src_tbl:t src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox dst_db:onlythisdb dst_tbl:t dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0 user:$ENV{USER} host:-*/
|
"DELETE FROM `onlythisdb`.`t` WHERE `i`='5' LIMIT 1 /*percona-toolkit src_db:onlythisdb src_tbl:t src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox dst_db:onlythisdb dst_tbl:t dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0 user:$ENV{USER} host:-*/
|
||||||
",
|
",
|
||||||
"Trace message appended to change SQL"
|
"Trace message appended to change SQL"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user