mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-12 22:19:44 +00:00
Make pt-archiver tests more reliable on weird, slow boxes like my vbox.
This commit is contained in:
@@ -34,7 +34,7 @@ use English qw(-no_match_vars);
|
|||||||
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
|
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Time::HiRes qw(usleep);
|
use Time::HiRes qw(sleep);
|
||||||
use POSIX qw(signal_h);
|
use POSIX qw(signal_h);
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
$Data::Dumper::Indent = 1;
|
$Data::Dumper::Indent = 1;
|
||||||
@@ -219,15 +219,14 @@ sub parse_file {
|
|||||||
# Wait until code returns true.
|
# Wait until code returns true.
|
||||||
sub wait_until {
|
sub wait_until {
|
||||||
my ( $code, $t, $max_t ) = @_;
|
my ( $code, $t, $max_t ) = @_;
|
||||||
my $slept = 0;
|
|
||||||
my $sleep_int = $t || .5;
|
|
||||||
$t ||= .5;
|
$t ||= .5;
|
||||||
$max_t ||= 5;
|
$max_t ||= 10;
|
||||||
$t *= 1_000_000;
|
|
||||||
|
my $slept = 0;
|
||||||
while ( $slept <= $max_t ) {
|
while ( $slept <= $max_t ) {
|
||||||
return if $code->();
|
return if $code->();
|
||||||
usleep($t);
|
sleep $t;
|
||||||
$slept += $sleep_int;
|
$slept += $t;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -255,6 +254,19 @@ sub wait_for {
|
|||||||
return 0;
|
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 {
|
sub _read {
|
||||||
my ( $fh ) = @_;
|
my ( $fh ) = @_;
|
||||||
return <$fh>;
|
return <$fh>;
|
||||||
|
@@ -42,4 +42,6 @@ cd $PERCONA_TOOLKIT_BRANCH/sandbox
|
|||||||
/tmp/$PORT/use < sakila-db/sakila-schema.sql
|
/tmp/$PORT/use < sakila-db/sakila-schema.sql
|
||||||
/tmp/$PORT/use < sakila-db/sakila-data.sql
|
/tmp/$PORT/use < sakila-db/sakila-data.sql
|
||||||
|
|
||||||
|
$PERCONA_TOOLKIT_BRANCH/sandbox/test-env reset
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -42,6 +42,7 @@ my $cmd = "$trunk/bin/pt-archiver";
|
|||||||
# Issue 758: Make mk-archiver wait for a slave
|
# Issue 758: Make mk-archiver wait for a slave
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
$sb->load_file('master', 't/pt-archiver/samples/issue_758.sql');
|
$sb->load_file('master', 't/pt-archiver/samples/issue_758.sql');
|
||||||
|
PerconaTest::wait_for_table($dbh2, "issue_758.t");
|
||||||
|
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$dbh->selectall_arrayref('select * from issue_758.t'),
|
$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,
|
# After this sleep the slave should have executed the INSERT SELECT,
|
||||||
# which returns 0, and the 2 purge/delete statments from above.
|
# which returns 0, and the 2 purge/delete statments from above.
|
||||||
sleep 1;
|
sleep 3;
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$dbh->selectall_arrayref('select * from issue_758.t'),
|
$dbh->selectall_arrayref('select * from issue_758.t'),
|
||||||
[[0]],
|
[[0]],
|
||||||
|
@@ -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.
|
# Bulk delete with limit that results in 2 chunks.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
$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($dbh, '`db`.`main_table-123`');
|
||||||
$dbh->do('use dm');
|
$dbh->do('use dm');
|
||||||
|
|
||||||
is_deeply(
|
is_deeply(
|
||||||
@@ -121,7 +122,7 @@ 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");
|
||||||
sleep 1;
|
PerconaTest::wait_for_table($slave_dbh, "`dm`.`main_table-123`");
|
||||||
|
|
||||||
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,6 +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');
|
||||||
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),
|
||||||
|
@@ -33,8 +33,9 @@ my $cnf = "/tmp/12345/my.sandbox.cnf";
|
|||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Issue 1152: mk-archiver columns option resulting in null archived table data
|
# Issue 1152: mk-archiver columns option resulting in null archived table data
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
|
||||||
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
|
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
|
||||||
|
PerconaTest::wait_for_table($dbh, 'issue_1225.t');
|
||||||
|
|
||||||
$dbh->do('set names "utf8"');
|
$dbh->do('set names "utf8"');
|
||||||
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
|
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
|
||||||
is_deeply(
|
is_deeply(
|
||||||
|
@@ -36,6 +36,8 @@ my $file = "/tmp/mk-archiver-file.txt";
|
|||||||
# archive to file
|
# archive to file
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
|
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
|
||||||
|
PerconaTest::wait_for_table($dbh, 'issue_1225.t');
|
||||||
|
|
||||||
$dbh->do('set names "utf8"');
|
$dbh->do('set names "utf8"');
|
||||||
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
|
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
|
||||||
is_deeply(
|
is_deeply(
|
||||||
|
@@ -85,6 +85,7 @@ SKIP: {
|
|||||||
|
|
||||||
# This test will achive rows from dbh:test.table_1 to dbh2:test.table_2.
|
# 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');
|
$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.
|
# Change passwords so defaults files won't work.
|
||||||
$dbh->do('SET PASSWORD FOR msandbox = PASSWORD("foo")');
|
$dbh->do('SET PASSWORD FOR msandbox = PASSWORD("foo")');
|
||||||
@@ -92,7 +93,7 @@ SKIP: {
|
|||||||
|
|
||||||
$dbh2->do('TRUNCATE TABLE test.table_2');
|
$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');
|
my $r = $dbh2->selectall_arrayref('SELECT * FROM test.table_2');
|
||||||
is(
|
is(
|
||||||
scalar @$r,
|
scalar @$r,
|
||||||
@@ -112,7 +113,6 @@ SKIP: {
|
|||||||
. 'status" and restart with "test-env restart". The error was: '
|
. 'status" and restart with "test-env restart". The error was: '
|
||||||
. $EVAL_ERROR);
|
. $EVAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
Reference in New Issue
Block a user