From 5a53f966c28908cdf238761f8011e25f28877d97 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Wed, 6 Dec 2017 11:18:25 -0300 Subject: [PATCH] PT-204 Added tests --- bin/pt-table-checksum | 11 +++--- lib/Sandbox.pm | 19 +++++++++ t/pt-table-checksum/pt-204.t | 75 ++++++++++++++++++++++++++++-------- 3 files changed, 84 insertions(+), 21 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 8061a2fd..89ef20ca 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -10110,21 +10110,22 @@ sub main { } } if ($not_ignored_rocks_db_tables_count > 0) { - print STDERR "\nThe MyRocks storage engine is not supported with pt-table-checksum " . - "since MyRocks does not support binlog_format=STATEMENT.\n". + print STDERR "\nThe RocksDB storage engine is not supported with pt-table-checksum " . + "since RocksDB does not support binlog_format=STATEMENT.\n". "We have identified the following tables using MyRocks storage engine:\n"; for my $row (@$rows) { print "$row->{table_schema}.$row->{table_name}\n"; } print STDERR "\nPlease add ROCKSDB to the list of --ignored-engines\n"; - print STDERR "--ignored-engines:FEDERATED,MRG_MyISAM,RocksDB\n"; + print STDERR "--ignored-engines=FEDERATED,MRG_MyISAM,RocksDB\n"; print STDERR "\nConversely exclude the MyRocks tables explicitly:\n"; print STDERR "--ignore-tables=$tables_list\n\n"; - die "Aborting"; + print STDERR "Aborting"; + exit($PTC_EXIT_STATUS{SKIP_TABLE}); } } } - print STDOUT "Staring checksum ...\n"; + print STDOUT "Starting checksum ...\n"; } # ######################################################################## # Set up the run time, if any. Anything that waits should check this diff --git a/lib/Sandbox.pm b/lib/Sandbox.pm index 10beafc0..a99e7b21 100644 --- a/lib/Sandbox.pm +++ b/lib/Sandbox.pm @@ -577,6 +577,25 @@ sub do_as_root { return $ok; } +sub has_engine { + my ( $self, $host, $want_engine ) = @_; + + # Get the current checksums on the host. + my $dbh = $self->get_dbh_for($host); + my $sql = "SHOW ENGINES"; + my @engines = @{$dbh->selectall_arrayref($sql, {Slice => {} })}; + + # Diff the two sets of checksums: host to master (ref). + my $has_engine=0; + foreach my $engine ( @engines ) { + if ( $engine->{engine} =~ m/$want_engine/i ) { + $has_engine=1; + last; + } + } + return $has_engine; +} + sub _d { my ($package, undef, $line) = caller 0; @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } diff --git a/t/pt-table-checksum/pt-204.t b/t/pt-table-checksum/pt-204.t index b44b74ec..1335c0ba 100644 --- a/t/pt-table-checksum/pt-204.t +++ b/t/pt-table-checksum/pt-204.t @@ -21,10 +21,11 @@ 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 => 4; + plan skip_all => 'Cannot connect to sandbox master'; +} elsif (!$sb->has_engine('master', 'ROCKSDB')) { + plan skip_all => 'These tests need RocksDB'; +} else { + plan tests => 9; } $sb->load_file('master', 't/pt-table-checksum/samples/pt-204.sql'); @@ -35,33 +36,75 @@ $sb->load_file('master', 't/pt-table-checksum/samples/pt-204.sql'); my $master_dsn = $sb->dsn_for('master'); my @args = ($master_dsn, "--set-vars", "innodb_lock_wait_timeout=50", "--no-check-binlog-format"); -my $output; -my $exit_status; +my ($output, $exit_status); # Test #1 -$output = output( +($output, $exit_status) = full_output( sub { $exit_status = pt_table_checksum::main(@args) }, stderr => 1, ); +diag("status: $exit_status"); + +is( + $exit_status, + 64, + "PT-204 Cannot checksum RocksDB tables. Exit status=64 -> SKIP_TABLE", +); + +like( + $output, + qr/Checking if all tables can be checksummed/, + "PT-204 Message before checksum starts", +); + +like( + $output, + qr/The RocksDB storage engine is not supported with pt-table-checksum/, + "PT-204 Error message: cannot checksum RocksDB tables", +); + +# Test #2 +($output, $exit_status) = full_output( + sub { $exit_status = pt_table_checksum::main(@args, qw(--ignore-tables test.t1)) }, + stderr => 1, +); + is( $exit_status, 0, - "PT-204 use single backtick in comments", -); - -unlike( - $output, - qr/test\.t1/, - "PT-204 table t1 was skipped (RocksDB)", + "PT-204 Starting checksum since RocksDB table was skipped with --ignore-tables", ); like( $output, - qr/test\.t2/, - "PT-204 table t2 was checksumed (InnoDB)", + qr/Starting checksum/, + 'PT-204 Got "Starting checksum" message', ); +unlike( + $output, + qr/test.t1/, + "PT-204 RocksDB table was really skipped with --ignore-tables", +); + +# Test #3 +($output, $exit_status) = full_output( + sub { $exit_status = pt_table_checksum::main(@args, qw(--ignore-engines RocksDB)) }, + stderr => 1, +); + +is( + $exit_status, + 0, + "PT-204 Starting checksum since RocksDB table was skipped with --ignore-engines", +); + +unlike( + $output, + qr/test.t1/, + "PT-204 RocksDB table was really skipped with --ignore-engines", +); # ############################################################################# # Done.