diff --git a/t/pt-table-checksum/basics.t b/t/pt-table-checksum/basics.t index e9b64000..eb947bbe 100644 --- a/t/pt-table-checksum/basics.t +++ b/t/pt-table-checksum/basics.t @@ -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. # ############################################################################# diff --git a/t/pt-table-checksum/fnv_64.t b/t/pt-table-checksum/fnv_64.t index 84702f2f..274e8082 100644 --- a/t/pt-table-checksum/fnv_64.t +++ b/t/pt-table-checksum/fnv_64.t @@ -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; diff --git a/t/pt-table-checksum/ignore_columns.t b/t/pt-table-checksum/ignore_columns.t index 78b8f7ce..a54c2586 100644 --- a/t/pt-table-checksum/ignore_columns.t +++ b/t/pt-table-checksum/ignore_columns.t @@ -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; diff --git a/t/pt-table-checksum/issue_1020.t b/t/pt-table-checksum/issue_1020.t deleted file mode 100644 index 7c88da7b..00000000 --- a/t/pt-table-checksum/issue_1020.t +++ /dev/null @@ -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;