Update ignore_columns.t. Move issue_1020.t tests into basics.t and remove issue_1020.t.

This commit is contained in:
Daniel Nichter
2011-10-13 11:31:46 -06:00
parent d27ede758d
commit 675efca692
4 changed files with 79 additions and 70 deletions

View File

@@ -31,7 +31,7 @@ elsif ( !@{$master_dbh->selectall_arrayref('show databases like "sakila"')} ) {
plan skip_all => 'sakila database is not loaded';
}
else {
plan tests => 5;
plan tests => 7;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
@@ -41,6 +41,7 @@ my @args = ($master_dsn, qw(--lock-wait-timeout 3));
my $row;
my $output;
my $exit_status;
my $sample = "t/pt-table-checksum/samples/";
my $outfile = '/tmp/pt-table-checksum-results';
my $repl_db = 'percona';
@@ -109,6 +110,35 @@ is(
'78 checksums on slave'
);
# ############################################################################
# --[no]replicate-check and, implicitly, the tool's exit status.
# ############################################################################
# Make one row on the slave differ.
$row = $slave_dbh->selectrow_arrayref("select city, last_update from sakila.city where city_id=1");
$slave_dbh->do("update sakila.city set city='test' where city_id=1");
$exit_status = pt_table_checksum::main(@args,
qw(--quiet --quiet -t sakila.city));
is(
$exit_status,
1,
"--replicate-check on by default, detects diff"
);
$exit_status = pt_table_checksum::main(@args,
qw(--quiet --quiet -t sakila.city --no-replicate-check));
is(
$exit_status,
0,
"--no-replicate-check, no diff detected"
);
# Restore the row on the slave, else other tests will fail.
$slave_dbh->do("update sakila.city set city='$row->[0]', last_update='$row->[1]' where city_id=1");
# #############################################################################
# Done.
# #############################################################################

View File

@@ -23,6 +23,9 @@ if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
# TODO Need to update this test file. I don't have MySQL dev on my box
# to compile the udf.
my $output;
my $cnf='/tmp/12345/my.sandbox.cnf';
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf -d test -t checksum_test 127.0.0.1";
@@ -33,7 +36,7 @@ eval { $master_dbh->do('DROP FUNCTION test.fnv_64'); };
eval { $master_dbh->do("CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'fnv_udf.so';"); };
if ( $EVAL_ERROR ) {
chomp $EVAL_ERROR;
plan skip_all => "Failed to created FNV_64 UDF: $EVAL_ERROR";
plan skip_all => "No FNV_64 UDF lib"
}
else {
plan tests => 5;

View File

@@ -27,37 +27,66 @@ elsif ( !$slave_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave';
}
else {
plan tests => 2;
plan tests => 3;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
# so we need to specify --lock-wait-timeout=3 else the tool will die.
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
my $output;
my $cnf='/tmp/12345/my.sandbox.cnf';
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
$sb->create_dbs($master_dbh, [qw(test)]);
$sb->load_file('master', 't/pt-table-checksum/samples/issue_94.sql');
# #############################################################################
# Issue 94: Enhance mk-table-checksum, add a --ignore-columns option
# #############################################################################
PerconaTest::wait_for_table($slave_dbh, 'test.issue_94', 'a=11');
$slave_dbh->do("update test.issue_94 set c=''");
$output = `$cmd -d test -t issue_94 P=12346 --algorithm ACCUM | awk '{print \$7}'`;
like(
sub get_diffs {
my ($output) = @_;
my (@diffs) = $output =~ m/
^\S+\s+ # TS
\d+\s+ # ERRORS
(\d+) # DIFFS
/gmx;
my $total_diffs = 0;
map { $total_diffs += $_ } @diffs;
return $total_diffs;
}
$output = output(
sub { pt_table_checksum::main(@args, qw(-d test -t issue_94)) },
trf => \&get_diffs,
);
is(
$output,
qr/CHECKSUM\n00000006B6BDB8E6\n00000006B6BDB8E6/,
'Checksum ok with all 3 columns (issue 94 1/2)'
"1",
"Diff when column not ignored"
);
$output = `$cmd -d test -t issue_94 P=12346 --algorithm ACCUM --ignore-columns c | awk '{print \$7}'`;
like(
$output = output(
sub { pt_table_checksum::main(@args, qw(-d test -t issue_94),
qw(--ignore-columns c)) },
trf => \&get_diffs,
);
is(
$output,
qr/CHECKSUM\n000000066094F8AA\n000000066094F8AA/,
'Checksum ok with ignored column (issue 94 2/2)'
"0",
"No diff when column ignored"
);
$output = output(
sub { pt_table_checksum::main(@args, qw(-d test -t issue_94),
qw(--ignore-columns c --explain)) },
);
unlike(
$output,
qr/`c`/,
"Ignored column is not in checksum query"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
$sb->wipe_clean($slave_dbh);
exit;

View File

@@ -1,53 +0,0 @@
#!/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 PerconaTest;
use Sandbox;
require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
else {
plan tests => 1;
}
my $output;
my $cnf = '/tmp/12345/my.sandbox.cnf';
$sb->create_dbs($dbh, [qw(test)]);
$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl.sql');
# #############################################################################
# Issue 1020: mk-table-checksum should not checksum with --replicate-check=0
# #############################################################################
$output = output(
sub { pt_table_checksum::main("F=$cnf", qw(--replicate=test.checksum --replicate-check=0)) },
stderr => 1,
);
is (
$output,
'',
"mk-table-checksum should not checksum with --replicate-check=0 (issue 1020)"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
exit;