Make pt-archiver tests more reliable on weird, slow boxes like my vbox.

This commit is contained in:
Daniel Nichter
2011-07-14 09:57:16 -06:00
parent c78beba647
commit db76b3ca30
9 changed files with 38 additions and 106 deletions

View File

@@ -34,7 +34,7 @@ use English qw(-no_match_vars);
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
use Test::More;
use Time::HiRes qw(usleep);
use Time::HiRes qw(sleep);
use POSIX qw(signal_h);
use Data::Dumper;
$Data::Dumper::Indent = 1;
@@ -219,15 +219,14 @@ sub parse_file {
# Wait until code returns true.
sub wait_until {
my ( $code, $t, $max_t ) = @_;
my $slept = 0;
my $sleep_int = $t || .5;
$t ||= .5;
$max_t ||= 5;
$t *= 1_000_000;
$max_t ||= 10;
my $slept = 0;
while ( $slept <= $max_t ) {
return if $code->();
usleep($t);
$slept += $sleep_int;
sleep $t;
$slept += $t;
}
return;
}
@@ -255,6 +254,19 @@ sub wait_for {
return 0;
}
sub wait_for_table {
my ($dbh, $tbl) = @_;
return wait_until(
sub {
my $r;
eval { $r = $dbh->selectrow_arrayref("SELECT 1 FROM $tbl"); };
return $EVAL_ERROR ? 0 : 1;
},
0.25,
15,
);
}
sub _read {
my ( $fh ) = @_;
return <$fh>;

View File

@@ -42,4 +42,6 @@ cd $PERCONA_TOOLKIT_BRANCH/sandbox
/tmp/$PORT/use < sakila-db/sakila-schema.sql
/tmp/$PORT/use < sakila-db/sakila-data.sql
$PERCONA_TOOLKIT_BRANCH/sandbox/test-env reset
exit 0

File diff suppressed because one or more lines are too long

View File

@@ -42,6 +42,7 @@ my $cmd = "$trunk/bin/pt-archiver";
# Issue 758: Make mk-archiver wait for a slave
# #############################################################################
$sb->load_file('master', 't/pt-archiver/samples/issue_758.sql');
PerconaTest::wait_for_table($dbh2, "issue_758.t");
is_deeply(
$dbh->selectall_arrayref('select * from issue_758.t'),
@@ -81,7 +82,7 @@ is_deeply(
# After this sleep the slave should have executed the INSERT SELECT,
# which returns 0, and the 2 purge/delete statments from above.
sleep 1;
sleep 3;
is_deeply(
$dbh->selectall_arrayref('select * from issue_758.t'),
[[0]],

View File

@@ -36,6 +36,7 @@ my $cmd = "perl -I $trunk/t/pt-archiver/samples $trunk/bin/pt-archiver";
# Bulk delete with limit that results in 2 chunks.
# ###########################################################################
$sb->load_file('master', "t/pt-archiver/samples/delete_more.sql");
PerconaTest::wait_for_table($dbh, '`db`.`main_table-123`');
$dbh->do('use dm');
is_deeply(
@@ -121,7 +122,7 @@ 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");
sleep 1;
PerconaTest::wait_for_table($slave_dbh, "`dm`.`main_table-123`");
is_deeply(
$slave_dbh->selectall_arrayref('select * from `main_table-123` order by id'),

View File

@@ -35,6 +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');
my $sql = 'select status, count(*) from gt_n.t1 group by status';
is_deeply(
$dbh->selectall_arrayref($sql),

View File

@@ -33,8 +33,9 @@ my $cnf = "/tmp/12345/my.sandbox.cnf";
# #############################################################################
# Issue 1152: mk-archiver columns option resulting in null archived table data
# #############################################################################
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
PerconaTest::wait_for_table($dbh, 'issue_1225.t');
$dbh->do('set names "utf8"');
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
is_deeply(

View File

@@ -36,6 +36,8 @@ my $file = "/tmp/mk-archiver-file.txt";
# archive to file
# #############################################################################
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
PerconaTest::wait_for_table($dbh, 'issue_1225.t');
$dbh->do('set names "utf8"');
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
is_deeply(

View File

@@ -85,6 +85,7 @@ SKIP: {
# This test will achive rows from dbh:test.table_1 to dbh2:test.table_2.
$sb->load_file('master', 't/pt-archiver/samples/tables1-4.sql');
PerconaTest::wait_for_table($dbh2, 'test.table_2');
# Change passwords so defaults files won't work.
$dbh->do('SET PASSWORD FOR msandbox = PASSWORD("foo")');
@@ -92,7 +93,7 @@ SKIP: {
$dbh2->do('TRUNCATE TABLE test.table_2');
$output = `MKDEBUG=1 $trunk/bin/pt-archiver --where 1=1 --source h=127.1,P=12345,D=test,t=table_1,u=msandbox,p=foo --dest P=12346,t=table_2 --statistics 2>&1`;
$output = `$trunk/bin/pt-archiver --where 1=1 --source h=127.1,P=12345,D=test,t=table_1,u=msandbox,p=foo --dest P=12346,t=table_2 2>&1`;
my $r = $dbh2->selectall_arrayref('SELECT * FROM test.table_2');
is(
scalar @$r,
@@ -112,7 +113,6 @@ SKIP: {
. 'status" and restart with "test-env restart". The error was: '
. $EVAL_ERROR);
}
};
# #############################################################################