Make t/pt-online-schema-change/alter-active-table.t less fickle, but still not 100% fixed

This commit is contained in:
Baron Schwartz
2012-06-06 16:45:13 -04:00
parent af38351e82
commit 4af46e81f9
2 changed files with 32 additions and 17 deletions

View File

@@ -15,7 +15,7 @@ use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-online-schema-change";
use Time::HiRes qw(usleep);
use Time::HiRes qw(sleep);
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
@@ -33,7 +33,7 @@ elsif ( !$slave_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave';
}
else {
plan tests => 8;
plan tests => 9;
}
my $output;
@@ -43,6 +43,7 @@ my $exit;
my $rows;
my $query_table_stop = "/tmp/query_table.$PID.stop";
my $query_table_pid = "/tmp/query_table.$PID.pid";
my $query_table_output = "/tmp/query_table.$PID.output";
sub start_query_table {
@@ -52,18 +53,23 @@ sub start_query_table {
diag(`echo > $query_table_output`);
my $cmd = "$trunk/$sample/query_table.pl";
system("$cmd 127.1 12345 $db $tbl $pkcol $query_table_stop >$query_table_output &");
system("$cmd 127.1 12345 $db $tbl $pkcol $query_table_stop $query_table_pid >$query_table_output &");
wait_until(sub{-e $query_table_pid});
return;
}
sub stop_query_table {
diag(`touch $query_table_stop`);
sleep 1;
open my $fh, '<', $query_table_pid or die $OS_ERROR;
my ($p) = <$fh>;
close $fh;
chomp $p;
wait_until(sub{!kill 0, $p});
return;
}
sub get_ids {
sub get_ids {
open my $fh, '<', $query_table_output
or die "Cannot open $query_table_output: $OS_ERROR";
my @lines = <$fh>;
@@ -77,7 +83,7 @@ sub get_ids {
}
return \%ids;
};
}
sub check_ids {
my ( $db, $tbl, $pkcol, $ids ) = @_;
@@ -149,15 +155,16 @@ sub check_ids {
# #############################################################################
# Load 500 rows.
diag('Loading sample dataset...');
$sb->load_file('master', "$sample/basic_no_fks.sql");
PerconaTest::wait_for_table($slave_dbh, "pt_osc.t");
$master_dbh->do("USE pt_osc");
$master_dbh->do("TRUNCATE TABLE t");
diag(`cp $trunk/t/pt-online-schema-change/samples/basic_no_fks.data /tmp`);
$master_dbh->do("LOAD DATA LOCAL INFILE '/tmp/basic_no_fks.data' INTO TABLE pt_osc.t");
diag(`rm -rf /tmp/basic_no_fks.data`);
PerconaTest::wait_for_table($slave_dbh, "pt_osc.t", "id=500");
$master_dbh->do("ANALYZE TABLE pt_osc.t");
$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-online-schema-change/samples/basic_no_fks.data' INTO TABLE t");
$master_dbh->do("ANALYZE TABLE t");
$sb->wait_for_slaves();
$rows = $master_dbh->selectrow_hashref('show master status');
diag('Binlog position before altering table: ', $rows->{file}, '/', $rows->{position});
# Start inserting, updating, and deleting rows at random.
start_query_table(qw(pt_osc t id));
@@ -171,9 +178,11 @@ $output = output(
stderr => 1,
);
# Stop altering the table.
# Stop changing the table's data.
stop_query_table();
like($output, qr/Successfully altered `pt_osc`.`t`/, 'Altered OK');
$rows = $master_dbh->selectall_hashref('SHOW TABLE STATUS FROM pt_osc', 'name');
is(
$rows->{t}->{engine},
@@ -198,8 +207,9 @@ check_ids(qw(pt_osc t id), get_ids());
# #############################################################################
# Done.
# #############################################################################
diag(`rm -rf $query_table_stop >/dev/null 2>&1`);
diag(`rm -rf $query_table_output >/dev/null 2>&1`);
unlink $query_table_stop or warn $OS_ERROR;
unlink $query_table_output or warn $OS_ERROR;
unlink $query_table_pid or warn $OS_ERROR;
$sb->wipe_clean($master_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;

View File

@@ -6,8 +6,13 @@ use English qw(-no_match_vars);
use DBI;
use Time::HiRes qw(usleep time);
my ($host, $port, $db, $tbl, $pkcol, $stop_file, $sleep_time) = @ARGV;
die "I need a stop_file argument" unless $stop_file;
my ($host, $port, $db, $tbl, $pkcol, $stop_file, $pid_file, $sleep_time) = @ARGV;
die "I need a pid_file argument" unless $pid_file;
open my $fh, '>', $pid_file or die $OS_ERROR;
print $fh $PID;
close $fh;
my $dbh = DBI->connect(
"DBI:mysql:$db;host=$host;port=$port;mysql_read_default_group=client",
'msandbox', 'msandbox',