mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-09 07:30:02 +00:00
First basic tests. Reset global var. Add post_pipeline to PercoaTest::no_diff().
This commit is contained in:
@@ -5216,11 +5216,14 @@ $Data::Dumper::Quotekeys = 0;
|
||||
|
||||
use sigtrap 'handler', \&sig_int, 'normal-signals';
|
||||
my $oktorun = 1;
|
||||
my $print_header = 1; # print headers once
|
||||
|
||||
sub main {
|
||||
@ARGV = @_; # set global ARGV for this package
|
||||
# Reset global vars else tests will fail in strange ways.
|
||||
@ARGV = @_;
|
||||
$oktorun = 1;
|
||||
$print_header = 1;
|
||||
|
||||
$oktorun = 1; # global, must reset else tests will fail
|
||||
my $exit_status = 0;
|
||||
|
||||
# ########################################################################
|
||||
@@ -5980,7 +5983,6 @@ sub exec_nibble {
|
||||
{
|
||||
my $line_fmt = "%14s %6s %6s %7s %7s %7s %7s %-s\n";
|
||||
my @headers = qw(TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE);
|
||||
my $print_header = 1; # print headers once
|
||||
|
||||
sub print_checksum_results {
|
||||
my (%args) = @_;
|
||||
@@ -6816,7 +6818,9 @@ should be printed, in percentage, seconds, or number of iterations.
|
||||
|
||||
Don't print anything to STDOUT.
|
||||
|
||||
=item --recheck
|
||||
=item --[no]recheck
|
||||
|
||||
default: yes
|
||||
|
||||
Re-checksum chunks that L<"--replicate-check"> found to be different.
|
||||
|
||||
|
@@ -492,6 +492,10 @@ sub no_diff {
|
||||
if ( my $trf = $args{trf} ) {
|
||||
`$trf $tmp_file_orig > $tmp_file`;
|
||||
}
|
||||
if ( my $post_pipe = $args{post_pipe} ) {
|
||||
`cat $tmp_file | $post_pipe > $tmp_file-2`;
|
||||
`mv $tmp_file-2 $tmp_file`;
|
||||
}
|
||||
if ( my $sed_args = $args{sed} ) {
|
||||
foreach my $sed_args ( @{$args{sed}} ) {
|
||||
`cat $tmp_file | sed $sed_args > $tmp_file-2`;
|
||||
|
@@ -11,6 +11,7 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use Data::Dumper;
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
require "$trunk/bin/pt-table-checksum";
|
||||
@@ -18,34 +19,34 @@ require "$trunk/bin/pt-table-checksum";
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
my $slave_dbh = $sb->get_dbh_for('slave1');
|
||||
|
||||
if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
elsif ( !$slave_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave1';
|
||||
}
|
||||
elsif ( !@{$master_dbh->selectall_arrayref('show databases like "sakila"')} ) {
|
||||
plan skip_all => 'sakila database is not loaded';
|
||||
}
|
||||
else {
|
||||
plan tests => 10;
|
||||
plan tests => 4;
|
||||
}
|
||||
|
||||
my $row;
|
||||
my ($output, $output2);
|
||||
my $cnf = '/tmp/12345/my.sandbox.cnf';
|
||||
my @args = ('-F', $cnf, qw(-d test -t checksum_test 127.0.0.1 --replicate test.checksum));
|
||||
my $dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||
|
||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
||||
$sb->load_file('master', 't/pt-table-checksum/samples/replicate.sql');
|
||||
my $row;
|
||||
my $output;
|
||||
my $sample = "t/pt-table-checksum/samples/";
|
||||
my $outfile = '/tmp/pt-table-checksum-results';
|
||||
my $repl_db = 'percona';
|
||||
|
||||
sub empty_repl_tbl {
|
||||
$master_dbh->do('truncate table test.checksum');
|
||||
wait_until(
|
||||
sub {
|
||||
my @rows;
|
||||
eval {
|
||||
@rows = $master_dbh->selectall_array("select * from test.checksum");
|
||||
};
|
||||
return 1 if @rows == 0;
|
||||
},
|
||||
);
|
||||
ok(1, "Empty checksum table");
|
||||
sub reset_repl_db {
|
||||
$master_dbh->do("drop database if exists $repl_db");
|
||||
$master_dbh->do("create database $repl_db");
|
||||
$master_dbh->do("use $repl_db");
|
||||
}
|
||||
|
||||
sub set_tx_isolation {
|
||||
@@ -77,77 +78,82 @@ sub set_binlog_format {
|
||||
);
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# Test that --replicate disables --lock, --wait and --slave-lag like the
|
||||
# docu says. Once it didn't and that lead to issue 51.
|
||||
# #############################################################################
|
||||
my $cmd = "$trunk/bin/pt-table-checksum";
|
||||
reset_repl_db();
|
||||
diag(`rm $outfile >/dev/null 2>&1`);
|
||||
|
||||
$output = `$cmd localhost --replicate test.checksum --help --wait 5`;
|
||||
like(
|
||||
$output,
|
||||
qr/--lock\s+FALSE/,
|
||||
"--replicate disables --lock"
|
||||
# ############################################################################
|
||||
# Default checksum, results
|
||||
# ############################################################################
|
||||
|
||||
# Check that without any special options (other than --create-replicate-table)
|
||||
# the tool runs without errors or warnings and checksums all tables.
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_table_checksum::main($dsn, '--create-replicate-table') },
|
||||
"$sample/default-results-5.1.txt",
|
||||
post_pipe => 'awk \'{print $2 " " $3 " " $4 " " $6 " " $8}\'',
|
||||
),
|
||||
"Default checksum"
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/--slave-lag\s+FALSE/,
|
||||
"--replicate disables --slave-lag"
|
||||
# On fast machines, the chunk size will probably be be auto-adjusted so
|
||||
# large that all tables will be done in a single chunk without an index.
|
||||
# Since this varies by default, there's no use checking the checksums
|
||||
# other than to ensure that there's at one for each table.
|
||||
$row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums");
|
||||
cmp_ok(
|
||||
$row->[0], '>=', 37,
|
||||
'At least 37 checksums'
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/--wait\s+\(No value\)/,
|
||||
"--replicate disables --wait"
|
||||
# ############################################################################
|
||||
# Static chunk size (disable --chunk-time)
|
||||
# ############################################################################
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_table_checksum::main($dsn, qw(--chunk-time 0)) },
|
||||
"$sample/static-chunk-size-results-5.1.txt",
|
||||
post_pipe => 'awk \'{print $2 " " $3 " " $4 " " $5 " " $6 " " $8}\'',
|
||||
),
|
||||
"Static chunk size (--chunk-time 0)"
|
||||
);
|
||||
|
||||
|
||||
# #############################################################################
|
||||
# Test basic --replicate functionality.
|
||||
# #############################################################################
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args, qw(--function sha1)) },
|
||||
);
|
||||
$output2 = `/tmp/12345/use --skip-column-names -e "select this_crc from test.checksum where tbl='checksum_test'"`;
|
||||
my ($cnt, $crc) = $output =~ m/checksum_test *\d+ \S+ \S+ *(\d+|NULL) *(\w+)/;
|
||||
chomp $output2;
|
||||
$row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums");
|
||||
is(
|
||||
$crc,
|
||||
$output2,
|
||||
'Write checksum to --replicate table'
|
||||
$row->[0],
|
||||
78,
|
||||
'78 checksums'
|
||||
);
|
||||
|
||||
|
||||
# #############################################################################
|
||||
# Issue 720: mk-table-checksum --replicate should set transaction isolation
|
||||
# level
|
||||
# #############################################################################
|
||||
SKIP: {
|
||||
skip "binlog_format test for MySQL v5.1+", 6
|
||||
unless $sandbox_version gt '5.0';
|
||||
|
||||
empty_repl_tbl();
|
||||
set_binlog_format('row');
|
||||
set_tx_isolation('read committed');
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args) },
|
||||
stderr => 1,
|
||||
);
|
||||
like(
|
||||
$output,
|
||||
qr/test\s+checksum_test\s+0\s+127.0.0.1\s+MyISAM\s+1\s+83dcefb7/,
|
||||
"Set session transaction isolation level repeatable read"
|
||||
);
|
||||
|
||||
set_binlog_format('statement');
|
||||
set_tx_isolation('repeatable read');
|
||||
}
|
||||
#SKIP: {
|
||||
# skip "binlog_format test for MySQL v5.1+", 6
|
||||
# unless $sandbox_version gt '5.0';
|
||||
#
|
||||
# empty_repl_tbl();
|
||||
# set_binlog_format('row');
|
||||
# set_tx_isolation('read committed');
|
||||
#
|
||||
# $output = output(
|
||||
# sub { pt_table_checksum::main(@args) },
|
||||
# stderr => 1,
|
||||
# );
|
||||
# like(
|
||||
# $output,
|
||||
# qr/test\s+checksum_test\s+0\s+127.0.0.1\s+MyISAM\s+1\s+83dcefb7/,
|
||||
# "Set session transaction isolation level repeatable read"
|
||||
# );
|
||||
#
|
||||
# set_binlog_format('statement');
|
||||
# set_tx_isolation('repeatable read');
|
||||
#}
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
#$sb->wipe_clean($master_dbh);
|
||||
exit;
|
||||
|
38
t/pt-table-checksum/samples/default-results-5.1.txt
Normal file
38
t/pt-table-checksum/samples/default-results-5.1.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
ERRORS DIFFS ROWS SKIPPED TABLE
|
||||
0 0 0 0 mysql.columns_priv
|
||||
0 0 3 0 mysql.db
|
||||
0 0 0 0 mysql.event
|
||||
0 0 0 0 mysql.func
|
||||
0 0 37 0 mysql.help_category
|
||||
0 0 310 0 mysql.help_keyword
|
||||
0 0 988 0 mysql.help_relation
|
||||
0 0 489 0 mysql.help_topic
|
||||
0 0 0 0 mysql.host
|
||||
0 0 0 0 mysql.ndb_binlog_index
|
||||
0 0 0 0 mysql.plugin
|
||||
0 0 6 0 mysql.proc
|
||||
0 0 0 0 mysql.procs_priv
|
||||
0 0 0 0 mysql.servers
|
||||
0 0 0 0 mysql.tables_priv
|
||||
0 0 0 0 mysql.time_zone
|
||||
0 0 0 0 mysql.time_zone_leap_second
|
||||
0 0 0 0 mysql.time_zone_name
|
||||
0 0 0 0 mysql.time_zone_transition
|
||||
0 0 0 0 mysql.time_zone_transition_type
|
||||
0 0 2 0 mysql.user
|
||||
0 0 200 0 sakila.actor
|
||||
0 0 603 0 sakila.address
|
||||
0 0 16 0 sakila.category
|
||||
0 0 600 0 sakila.city
|
||||
0 0 109 0 sakila.country
|
||||
0 0 599 0 sakila.customer
|
||||
0 0 1000 0 sakila.film
|
||||
0 0 5462 0 sakila.film_actor
|
||||
0 0 1000 0 sakila.film_category
|
||||
0 0 1000 0 sakila.film_text
|
||||
0 0 4581 0 sakila.inventory
|
||||
0 0 6 0 sakila.language
|
||||
0 0 16049 0 sakila.payment
|
||||
0 0 16044 0 sakila.rental
|
||||
0 0 2 0 sakila.staff
|
||||
0 0 2 0 sakila.store
|
@@ -0,0 +1,38 @@
|
||||
ERRORS DIFFS ROWS CHUNKS SKIPPED TABLE
|
||||
0 0 0 1 0 mysql.columns_priv
|
||||
0 0 3 1 0 mysql.db
|
||||
0 0 0 1 0 mysql.event
|
||||
0 0 0 1 0 mysql.func
|
||||
0 0 37 1 0 mysql.help_category
|
||||
0 0 310 1 0 mysql.help_keyword
|
||||
0 0 988 1 0 mysql.help_relation
|
||||
0 0 489 1 0 mysql.help_topic
|
||||
0 0 0 1 0 mysql.host
|
||||
0 0 0 1 0 mysql.ndb_binlog_index
|
||||
0 0 0 1 0 mysql.plugin
|
||||
0 0 6 1 0 mysql.proc
|
||||
0 0 0 1 0 mysql.procs_priv
|
||||
0 0 0 1 0 mysql.servers
|
||||
0 1 0 1 0 mysql.tables_priv
|
||||
0 0 0 1 0 mysql.time_zone
|
||||
0 0 0 1 0 mysql.time_zone_leap_second
|
||||
0 0 0 1 0 mysql.time_zone_name
|
||||
0 0 0 1 0 mysql.time_zone_transition
|
||||
0 0 0 1 0 mysql.time_zone_transition_type
|
||||
0 0 2 1 0 mysql.user
|
||||
0 0 200 1 0 sakila.actor
|
||||
0 0 603 1 0 sakila.address
|
||||
0 0 16 1 0 sakila.category
|
||||
0 0 600 1 0 sakila.city
|
||||
0 0 109 1 0 sakila.country
|
||||
0 0 599 1 0 sakila.customer
|
||||
0 0 1000 1 0 sakila.film
|
||||
0 0 5462 6 0 sakila.film_actor
|
||||
0 0 1000 1 0 sakila.film_category
|
||||
0 0 1000 1 0 sakila.film_text
|
||||
0 0 4581 5 0 sakila.inventory
|
||||
0 0 6 1 0 sakila.language
|
||||
0 0 16049 17 0 sakila.payment
|
||||
0 0 16044 17 0 sakila.rental
|
||||
0 0 2 1 0 sakila.staff
|
||||
0 0 2 1 0 sakila.store
|
Reference in New Issue
Block a user