mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-28 00:21:56 +00:00
Test comparing results to host.
This commit is contained in:
@@ -6073,6 +6073,8 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
use Lmo;
|
||||
|
||||
has 'dir' => (
|
||||
@@ -6144,7 +6146,10 @@ sub next {
|
||||
my $results = <$_results_fh>;
|
||||
my $rows = <$_rows_fh>;
|
||||
|
||||
return unless $query;
|
||||
if ( !$query ) {
|
||||
PTDEBUG && _d('No more results');
|
||||
return;
|
||||
}
|
||||
|
||||
chomp($query);
|
||||
|
||||
@@ -6170,6 +6175,7 @@ sub next {
|
||||
$results->{query} = $query;
|
||||
$results->{rows} = $rows;
|
||||
|
||||
PTDEBUG && _d('Results:', Dumper($results));
|
||||
return $results;
|
||||
}
|
||||
|
||||
@@ -6206,7 +6212,7 @@ use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
sub new {
|
||||
my ( $class, $rows ) = @_;
|
||||
my $n_rows = scalar @$rows;
|
||||
my $n_rows = $rows && ref $rows eq 'ARRAY' ? scalar @$rows : 0;
|
||||
my $self = {
|
||||
rows => $rows,
|
||||
n_rows => $n_rows,
|
||||
@@ -6273,6 +6279,7 @@ sub main {
|
||||
queries_no_diffs => 0,
|
||||
queries_with_errors => 0,
|
||||
failed_queries => 0,
|
||||
not_select => 0,
|
||||
};
|
||||
|
||||
# ##########################################################################
|
||||
@@ -6670,7 +6677,6 @@ sub compare_host_to_host {
|
||||
my $results2 = $executor->exec_event(
|
||||
event => $event,
|
||||
host => $host2,
|
||||
database => $host1->{current_db},
|
||||
);
|
||||
|
||||
save_and_report_results(
|
||||
@@ -6794,10 +6800,13 @@ sub compare_results_to_host {
|
||||
);
|
||||
|
||||
while ( my $results1 = $result_iter->next() ) {
|
||||
$stats->{queries_read}++;
|
||||
|
||||
$results1->{sth} = FakeSth->new($results1->{rows});
|
||||
|
||||
my $event = {
|
||||
arg => $results1->{query},
|
||||
db => $results1->{db},
|
||||
fingerprint => $qr->fingerprint($results1->{query}),
|
||||
};
|
||||
|
||||
|
@@ -27,7 +27,7 @@ use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
sub new {
|
||||
my ( $class, $rows ) = @_;
|
||||
my $n_rows = scalar @$rows;
|
||||
my $n_rows = $rows && ref $rows eq 'ARRAY' ? scalar @$rows : 0;
|
||||
my $self = {
|
||||
rows => $rows,
|
||||
n_rows => $n_rows,
|
||||
|
@@ -25,6 +25,8 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
use Lmo;
|
||||
|
||||
has 'dir' => (
|
||||
@@ -96,7 +98,10 @@ sub next {
|
||||
my $results = <$_results_fh>;
|
||||
my $rows = <$_rows_fh>;
|
||||
|
||||
return unless $query;
|
||||
if ( !$query ) {
|
||||
PTDEBUG && _d('No more results');
|
||||
return;
|
||||
}
|
||||
|
||||
chomp($query);
|
||||
|
||||
@@ -122,6 +127,7 @@ sub next {
|
||||
$results->{query} = $query;
|
||||
$results->{rows} = $rows;
|
||||
|
||||
PTDEBUG && _d('Results:', Dumper($results));
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
130
t/pt-upgrade/compare_results.t
Normal file
130
t/pt-upgrade/compare_results.t
Normal file
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use File::Basename;
|
||||
use File::Temp qw(tempdir);
|
||||
|
||||
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
|
||||
|
||||
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`);
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $dbh1 = $sb->get_dbh_for('host1');
|
||||
my $dbh2 = $sb->get_dbh_for('host2');
|
||||
|
||||
if ( !$dbh1 ) {
|
||||
plan skip_all => 'Cannot connect to sandbox host1';
|
||||
}
|
||||
elsif ( !$dbh2 ) {
|
||||
plan skip_all => 'Cannot connect to sandbox host2';
|
||||
}
|
||||
|
||||
my $host1_dsn = $sb->dsn_for('host1');
|
||||
my $host2_dsn = $sb->dsn_for('host2');
|
||||
|
||||
my $tmpdir = tempdir("/tmp/pt-upgrade.$PID.XXXXXX", CLEANUP => 1);
|
||||
|
||||
my $sample = "t/pt-upgrade/samples";
|
||||
my $samples_dir = "$trunk/t/pt-upgrade/samples";
|
||||
|
||||
opendir(my $dh, $samples_dir) or die "Cannot open $samples_dir: $OS_ERROR";
|
||||
|
||||
sub load_sample_sql_files {
|
||||
my ($sampleno) = @_;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
while ( my $sampleno = readdir $dh ) {
|
||||
next unless $sampleno =~ m/^\d+$/;
|
||||
|
||||
my $conf = "$samples_dir/$sampleno/conf";
|
||||
|
||||
load_sample_sql_files($sampleno);
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
diag(`rm -rf $tmpdir/*`);
|
||||
|
||||
# First, run the log on host1 and save the results.
|
||||
my $save_results_output = output(
|
||||
sub { pt_upgrade::main(
|
||||
(-f $conf ? ('--config', $conf) : ()),
|
||||
$log,
|
||||
$host1_dsn,
|
||||
'--save-results', $tmpdir
|
||||
) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
# Second, compare the results to host2.
|
||||
my $output = output(
|
||||
sub { pt_upgrade::main(
|
||||
(-f $conf ? ('--config', $conf) : ()),
|
||||
$tmpdir,
|
||||
$host2_dsn,
|
||||
) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
my $file
|
||||
= -f "$samples_dir/$sampleno/${basename}_results.txt" ? "${basename}_results.txt"
|
||||
: -f "$samples_dir/$sampleno/${basename}.txt" ? "${basename}.txt"
|
||||
: undef;
|
||||
if ( $file ) {
|
||||
ok(
|
||||
no_diff(
|
||||
$output,
|
||||
"$sample/$sampleno/$file",
|
||||
cmd_output => 1,
|
||||
($sed ? (sed => [ $sed ]) : ()),
|
||||
),
|
||||
"$sampleno: $basename.txt"
|
||||
) or diag("\n\n---- DIFF ----\n\n", $test_diff,
|
||||
"\n\n---- SAVE RESULTS ----\n\n", $save_results_output,
|
||||
`cat $tmpdir/*`, "\n",
|
||||
"\n\n---- OUTPUT ----\n\n", $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close $dh;
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
#$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;
|
12
t/pt-upgrade/samples/001/insert_results.txt
Normal file
12
t/pt-upgrade/samples/001/insert_results.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 0
|
||||
queries_with_diffs 0
|
||||
queries_with_errors 0
|
@@ -4,6 +4,7 @@
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 1
|
||||
queries_read 1
|
||||
|
@@ -28,6 +28,7 @@ select * from test.t order by id
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
|
@@ -31,6 +31,7 @@ INSERT INTO t (id, username) VALUES (NULL, 'long_username')
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
|
@@ -27,6 +27,7 @@ SELECT (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP('2012-09-16 10:16:36')) / 60, SLE
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
|
@@ -27,6 +27,7 @@ select nonexistent_col from test.t
|
||||
########################################################################
|
||||
|
||||
failed_queries 1
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
|
@@ -29,6 +29,7 @@ select host2_col from test.t
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
|
@@ -29,6 +29,7 @@ select host1_col from test.t
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
|
Reference in New Issue
Block a user