Fix and make tests more reliable.

This commit is contained in:
Daniel Nichter
2011-07-14 11:05:05 -06:00
parent db76b3ca30
commit 7526f97224
8 changed files with 40 additions and 32 deletions

View File

@@ -255,12 +255,17 @@ sub wait_for {
}
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(
sub {
my $r;
eval { $r = $dbh->selectrow_arrayref("SELECT 1 FROM $tbl"); };
return $EVAL_ERROR ? 0 : 1;
eval { $r = $dbh->selectrow_arrayref($sql); };
return 0 if $EVAL_ERROR;
if ( $where ) {
return 0 unless $r && @$r;
}
return 1;
},
0.25,
15,

File diff suppressed because one or more lines are too long

View File

@@ -122,7 +122,8 @@ SKIP: {
# Run it again without DSN b so changes should be made on slave.
$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(
$slave_dbh->selectall_arrayref('select * from `main_table-123` order by id'),

View File

@@ -35,7 +35,7 @@ my $cmd = "$trunk/bin/pt-archiver";
# Test the custom plugin gt_n.
# ###########################################################################
$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';
is_deeply(
$dbh->selectall_arrayref($sql),

View File

@@ -32,42 +32,42 @@ SKIP: {
# There's no hung queries so we'll just make sure it outputs anything,
# its debug stuff in this case.
`$cmd --print --interval 1s --run-time 2 --pid /tmp/mk-kill.pid --log /tmp/mk-kill.log --daemonize`;
$output = `ps -eaf | grep 'mk-kill \-F'`;
`$cmd --print --interval 1s --run-time 2 --pid /tmp/pt-kill.pid --log /tmp/pt-kill.log --daemonize`;
$output = `ps -eaf | grep 'pt-kill \-F'`;
like(
$output,
qr/mk-kill -F /,
qr/pt-kill -F /,
'It lives daemonized'
);
ok(
-f '/tmp/mk-kill.pid',
-f '/tmp/pt-kill.pid',
'PID file created'
);
ok(
-f '/tmp/mk-kill.log',
-f '/tmp/pt-kill.log',
'Log file created'
);
sleep 2;
ok(
!-f '/tmp/mk-kill.pid',
!-f '/tmp/pt-kill.pid',
'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
# #########################################################################
`touch /tmp/mk-script.pid`;
$output = `$cmd $trunk/t/lib/samples/pl/recset006.txt --match-state Locked --print --pid /tmp/mk-script.pid 2>&1`;
`touch /tmp/pt-script.pid`;
$output = `$cmd $trunk/t/lib/samples/pl/recset006.txt --match-state Locked --print --pid /tmp/pt-script.pid 2>&1`;
like(
$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)'
);
`rm -rf /tmp/mk-script.pid`;
`rm -rf /tmp/pt-script.pid`;
# #############################################################################
# Done.

View File

@@ -90,7 +90,7 @@ ok(
'--report-format', 'query_report,profile',
"$trunk/t/lib/samples/slowlogs/slow007.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',
);

View File

@@ -52,18 +52,20 @@ $master_dbh->do('create table t (i int, unique index (i))');
$master_dbh->do('insert into t values (1),(2)');
$slave_dbh->do('insert into t values (3)');
PerconaTest::wait_for_table($slave_dbh, 'test.t', 'i=1');
is_deeply(
$master_dbh->selectall_arrayref('select * from test.t'),
$master_dbh->selectall_arrayref('select * from test.t order by i'),
[[1],[2]],
'Data on master before sync'
);
use Data::Dumper;
my $rows = $slave_dbh->selectall_arrayref('select * from test.t order by i');
is_deeply(
$slave_dbh->selectall_arrayref('select * from test.t'),
$rows,
[[1],[2],[3]],
'Data on slave before sync'
);
) or print Dumper($rows);
$master_dbh->do('SET GLOBAL binlog_format="ROW"');
$master_dbh->disconnect();

View File

@@ -51,12 +51,12 @@ output(
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/host:\S+?\*/host:-*/ if $output;
is(
$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"
);