mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-21 11:30:24 +00:00
Test pt-upgrade host-to-host. Implement diff_query_times(). Export $test_diff from PerconaTest instead of doing diag() in no_diff().
This commit is contained in:
@@ -4,201 +4,95 @@ BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use File::Basename;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
require "$trunk/bin/pt-upgrade";
|
||||
|
||||
# This runs immediately if the server is already running, else it starts it.
|
||||
diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`);
|
||||
# diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`);
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $dbh1 = $sb->get_dbh_for('master');
|
||||
my $dbh2 = $sb->get_dbh_for('master1');
|
||||
my $dbh1 = $sb->get_dbh_for('host1');
|
||||
my $dbh2 = $sb->get_dbh_for('host2');
|
||||
|
||||
if ( !$dbh1 ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
plan skip_all => 'Cannot connect to sandbox host1';
|
||||
}
|
||||
elsif ( !$dbh2 ) {
|
||||
plan skip_all => 'Cannot connect to second sandbox master';
|
||||
plan skip_all => 'Cannot connect to sandbox host2';
|
||||
}
|
||||
|
||||
my @host_args = ('h=127.1,P=12345,L=1', 'P=12348');
|
||||
my @op_args = (qw(-u msandbox -p msandbox),
|
||||
'--compare', 'results,warnings',
|
||||
'--zero-query-times',
|
||||
);
|
||||
my @args = (@host_args, @op_args);
|
||||
my $sample = "t/pt-upgrade/samples";
|
||||
my $log = "$trunk/$sample";
|
||||
my $host1_dsn = $sb->dsn_for('host1');
|
||||
my $host2_dsn = $sb->dsn_for('host2');
|
||||
|
||||
# ###########################################################################
|
||||
# Basic run.
|
||||
# ###########################################################################
|
||||
$sb->load_file('master', "$sample/001/tables.sql");
|
||||
$sb->load_file('master1', "$sample/001/tables.sql");
|
||||
my $sample = "t/pt-upgrade/samples";
|
||||
my $samples_dir = "$trunk/t/pt-upgrade/samples";
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args, "$log/001/select-one.log") },
|
||||
"$sample/001/select-one.txt",
|
||||
),
|
||||
'Report for a single query (checksum method)'
|
||||
);
|
||||
opendir(my $dh, $samples_dir) or die "Cannot open $samples_dir: $OS_ERROR";
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args, "$log/001/select-everyone.log") },
|
||||
"$sample/001/select-everyone.txt"
|
||||
),
|
||||
'Report for multiple queries (checksum method)'
|
||||
);
|
||||
while ( my $sampleno = readdir $dh ) {
|
||||
next unless $sampleno =~ m/^\d+$/;
|
||||
if ( -f "$samples_dir/$sampleno/tables.sql" ) {
|
||||
$sb->load_file('host1', "$sample/$sampleno/tables.sql", undef, no_wait => 1);
|
||||
$sb->load_file('host2', "$sample/$sampleno/tables.sql", undef, no_wait => 1);
|
||||
}
|
||||
if ( -f "$samples_dir/$sampleno/host1.sql" ) {
|
||||
$sb->load_file('host1', "$sample/$sampleno/host1.sql", undef, no_wait => 1);
|
||||
}
|
||||
if ( -f "$samples_dir/$sampleno/host2.sql" ) {
|
||||
$sb->load_file('host2', "$sample/$sampleno/host2.sql", undef, no_wait => 1);
|
||||
}
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-one.log",
|
||||
"--compare-results-method", "rows") },
|
||||
"$sample/001/select-one-rows.txt"
|
||||
),
|
||||
'Report for a single query (rows method)'
|
||||
);
|
||||
my $conf = "$samples_dir/$sampleno/conf";
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-everyone.log",
|
||||
"--compare-results-method", "rows") },
|
||||
"$sample/001/select-everyone-rows.txt"
|
||||
),
|
||||
'Report for multiple queries (rows method)'
|
||||
);
|
||||
foreach my $log ( glob("$samples_dir/$sampleno/*.log") ) {
|
||||
(my $basename = basename($log)) =~ s/\.\S+$//;
|
||||
my $sed;
|
||||
if ( -f "$samples_dir/$sampleno/$basename.sed" ) {
|
||||
chomp($sed = `cat $samples_dir/$sampleno/$basename.sed`);
|
||||
}
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-everyone.log",
|
||||
"--reports", "queries,differences,errors") },
|
||||
"$sample/001/select-everyone-no-stats.txt"
|
||||
),
|
||||
'Report without statistics'
|
||||
);
|
||||
my $output = output(
|
||||
sub { pt_upgrade::main(
|
||||
(-f $conf ? ('--config', $conf) : ()),
|
||||
$log,
|
||||
$host1_dsn,
|
||||
$host2_dsn,
|
||||
) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-everyone.log",
|
||||
"--reports", "differences,errors,statistics") },
|
||||
"$sample/001/select-everyone-no-queries.txt"
|
||||
),
|
||||
'Report without per-query reports'
|
||||
);
|
||||
if ( -f "$samples_dir/$sampleno/$basename.txt" ) {
|
||||
ok(
|
||||
no_diff(
|
||||
$output,
|
||||
"$sample/$sampleno/$basename.txt",
|
||||
cmd_output => 1,
|
||||
($sed ? (sed => [ $sed ]) : ()),
|
||||
),
|
||||
"$sampleno: $basename.txt"
|
||||
) or diag("diff:\n", $test_diff, "\noutput:\n", $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sb->wipe_clean($dbh1);
|
||||
$sb->wipe_clean($dbh2);
|
||||
|
||||
# #############################################################################
|
||||
# Issue 951: mk-upgrade "I need a db argument" error with
|
||||
# compare-results-method=rows
|
||||
# #############################################################################
|
||||
$sb->load_file('master', "$sample/002/tables.sql");
|
||||
$sb->load_file('master1', "$sample/002/tables.sql");
|
||||
|
||||
# Make a difference on one host so diff_rows() is called.
|
||||
$dbh1->do('insert into test.t values (5)');
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@op_args, "$log/002/no-db.log",
|
||||
'h=127.1,P=12345,D=test,L=1', 'P=12348,D=test',
|
||||
qw(--compare-results-method rows --temp-database test)) },
|
||||
"$sample/002/report-01.txt",
|
||||
),
|
||||
'No db, compare results row, DSN D, --temp-database (issue 951)'
|
||||
);
|
||||
|
||||
$sb->load_file('master', "$sample/002/tables.sql");
|
||||
$sb->load_file('master1', "$sample/002/tables.sql");
|
||||
$dbh1->do('insert into test.t values (5)');
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@op_args, "$log/002/no-db.log",
|
||||
'h=127.1,P=12345,D=test,L=1', 'P=12348,D=test',
|
||||
qw(--compare-results-method rows --temp-database tmp_db)) },
|
||||
"$sample/002/report-01.txt",
|
||||
),
|
||||
'No db, compare results row, DSN D'
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$dbh1->selectall_arrayref('show tables from `test`'),
|
||||
[['t']],
|
||||
"Didn't create temp table in event's db"
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$dbh1->selectall_arrayref('show tables from `tmp_db`'),
|
||||
[['mk_upgrade_left']],
|
||||
"Createed temp table in --temp-database"
|
||||
);
|
||||
|
||||
$sb->wipe_clean($dbh1);
|
||||
$sb->wipe_clean($dbh2);
|
||||
|
||||
# #############################################################################
|
||||
# Bug 926598: DBD::mysql bug causes pt-upgrade to use wrong
|
||||
# precision (M) and scale (D)
|
||||
# #############################################################################
|
||||
$sb->load_file('master', "$sample/003/tables.sql");
|
||||
$sb->load_file('master1', "$sample/003/tables.sql");
|
||||
|
||||
# Make a difference on one host so diff_rows() is called.
|
||||
$dbh1->do('insert into test.t values (4, 1.00)');
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args, "$log/003/double.log",
|
||||
qw(--compare-results-method rows)) },
|
||||
"$sample/003/report001.txt",
|
||||
),
|
||||
'M, D diff (bug 926598)',
|
||||
);
|
||||
|
||||
my $row = $dbh1->selectrow_arrayref("show create table test.mk_upgrade_left");
|
||||
like(
|
||||
$row->[1],
|
||||
qr/[`"]SUM\(total\)[`"]\s+double\sDEFAULT/i,
|
||||
"No M,D in table def (bug 926598)"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# SELECT FUNC(), so there are no tables.
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1060774
|
||||
# #############################################################################
|
||||
$sb->load_file('master', "$sample/004/tables.sql");
|
||||
$sb->load_file('master1', "$sample/004/tables.sql");
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_upgrade::main(@args,
|
||||
qw(--compare-results-method rows),
|
||||
qw(--no-clear-warnings),
|
||||
"$log/004/select-func.log") },
|
||||
"$sample/004/select-func.txt",
|
||||
),
|
||||
'SELECT FUNC() (bug 1060774)'
|
||||
);
|
||||
close $dh;
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
diag(`rm /tmp/left-outfile.txt /tmp/right-outfile.txt 2>/dev/null`);
|
||||
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
|
||||
$sb->wipe_clean($dbh1);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
#$sb->wipe_clean($dbh2);
|
||||
#$sb->wipe_clean($dbh1);
|
||||
#diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
|
||||
#ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
Reference in New Issue
Block a user