mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 23:45:44 +00:00
PT-2141 fix tests for pt-archiver (#581)
* PT-2141 Fix tests for pt-archiver Fixed tests t/pt-archiver/bulk_insert.t, t/pt-archiver/issue_1225.t, t/pt-archiver/issue_1229.t Their failures were due to change of utf8 alias from utf8mb3 in MySQL 5.7 to utf8mb4 in MySQL 8.0. And also due to character set match check between connection ad source table. * PT-2141 Fix tests for pt-archiver Removed test for PT-1898, because it was broken from the beginning: - it called pt-online-schema-change instead of pt-archiver - it announced it will run 6 tests while was running only 2 - the test case itself did not test the issue, described in PT-1898
This commit is contained in:
@@ -103,9 +103,13 @@ for my $char ( "\N{KATAKANA LETTER NI}", "\N{U+DF}" ) {
|
||||
my $sql = qq{INSERT INTO `bug_1127450`.`original` VALUES (1, ?)};
|
||||
$utf8_dbh->prepare($sql)->execute($char);
|
||||
|
||||
# We need to have --no-check-charset here, because utf8 that we use in the test file
|
||||
# is alias of utf8mb3 in 5.7 and alias of utf8mb4 in 8.0.
|
||||
# We cannot set this character set explicitly due to Perl limitations.
|
||||
# Changing utf8 to utf8mb4 will break test on 5.7
|
||||
$output = output(
|
||||
sub { pt_archiver::main(qw(--no-ascend --limit 50 --bulk-insert),
|
||||
qw(--bulk-delete --where 1=1 --statistics --charset utf8),
|
||||
qw(--bulk-delete --where 1=1 --statistics --charset utf8 --no-check-charset),
|
||||
'--source', "L=1,D=bug_1127450,t=original,F=$cnf",
|
||||
'--dest', "t=copy") }, stderr => 1
|
||||
);
|
||||
|
@@ -23,11 +23,15 @@ my $dbh = $sb->get_dbh_for('master');
|
||||
if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
elsif ($sandbox_version gt '5.7') {
|
||||
plan tests => 4;
|
||||
}
|
||||
else {
|
||||
plan tests => 5;
|
||||
}
|
||||
|
||||
my $output;
|
||||
my $archived_rows;
|
||||
|
||||
# #############################################################################
|
||||
# Issue 1152: mk-archiver columns option resulting in null archived table data
|
||||
@@ -57,7 +61,6 @@ SKIP: {
|
||||
"--check-charset"
|
||||
);
|
||||
|
||||
}
|
||||
$output = output(
|
||||
sub { pt_archiver::main(
|
||||
'--source', 'h=127.1,P=12345,D=issue_1225,t=t,u=msandbox,p=msandbox',
|
||||
@@ -66,12 +69,13 @@ $output = output(
|
||||
},
|
||||
);
|
||||
|
||||
my $archived_rows = $dbh->selectall_arrayref('select c from issue_1225.a limit 2');
|
||||
$archived_rows = $dbh->selectall_arrayref('select c from issue_1225.a limit 2');
|
||||
|
||||
ok(
|
||||
$original_rows->[0]->[0] ne $archived_rows->[0]->[0],
|
||||
"UTF8 characters lost when cxn isn't also UTF8"
|
||||
);
|
||||
}
|
||||
|
||||
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
|
||||
|
||||
@@ -79,7 +83,7 @@ $output = output(
|
||||
sub { pt_archiver::main(
|
||||
'--source', 'h=127.1,P=12345,D=issue_1225,t=t,u=msandbox,p=msandbox',
|
||||
'--dest', 't=a',
|
||||
qw(--where 1=1 --purge -A utf8)) # -A utf8 makes it work
|
||||
qw(--no-check-charset --where 1=1 --purge -A utf8)) # -A utf8 makes it work
|
||||
},
|
||||
);
|
||||
|
||||
|
@@ -33,7 +33,7 @@ elsif ( $DBD::mysql::VERSION lt '4' ) {
|
||||
my $output;
|
||||
my $rows;
|
||||
my $cnf = "/tmp/12345/my.sandbox.cnf";
|
||||
my $file = "/tmp/mk-archiver-file.txt";
|
||||
my $file = "/tmp/pt-archiver-file.txt";
|
||||
|
||||
# #############################################################################
|
||||
# Issue 1229: mk-archiver not creating UTF8 compatible file handles for
|
||||
@@ -53,11 +53,15 @@ is_deeply(
|
||||
|
||||
diag(`rm -rf $file >/dev/null`);
|
||||
|
||||
# We need to have --no-check-charset here, because utf8 that we use in the test file
|
||||
# is alias of utf8mb3 in 5.7 and alias of utf8mb4 in 8.0.
|
||||
# We cannot set this character set explicitly due to Perl limitations.
|
||||
# Changing utf8 to utf8mb4 will break test on 5.7
|
||||
$output = output(
|
||||
sub { pt_archiver::main(
|
||||
'--source', 'h=127.1,P=12345,D=issue_1225,t=t,u=msandbox,p=msandbox',
|
||||
'--file', $file,
|
||||
qw(--where 1=1 -A UTF8)) # -A utf8 makes it work
|
||||
qw(--no-check-charset --where 1=1 -A UTF8)) # -A utf8 makes it work
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
@@ -1,109 +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 threads;
|
||||
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use Data::Dumper;
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use SqlModes;
|
||||
use File::Temp qw/ tempdir tempfile /;
|
||||
|
||||
if ($ENV{PERCONA_SLOW_BOX}) {
|
||||
plan skip_all => 'This test needs a fast machine';
|
||||
} else {
|
||||
plan tests => 6;
|
||||
#plan skip_all => 'This test is taking too much time even in fast machines';
|
||||
}
|
||||
|
||||
our $delay = 15;
|
||||
|
||||
my $tmp_file = File::Temp->new();
|
||||
my $tmp_file_name = $tmp_file->filename;
|
||||
unlink $tmp_file_name;
|
||||
|
||||
require "$trunk/bin/pt-archiver";
|
||||
|
||||
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');
|
||||
my $master_dsn = 'h=127.0.0.1,P=12345,u=msandbox,p=msandbox';
|
||||
my $slave_dsn = 'h=127.0.0.1,P=12346,u=msandbox,p=msandbox';
|
||||
|
||||
sub reset_query_cache {
|
||||
my @dbhs = @_;
|
||||
return if ($sandbox_version >= '8.0');
|
||||
foreach my $dbh (@dbhs) {
|
||||
$dbh->do('RESET QUERY CACHE');
|
||||
}
|
||||
}
|
||||
|
||||
# 1) Set the slave delay to 0 just in case we are re-running the tests without restarting the sandbox.
|
||||
# 2) Load sample data
|
||||
# 3) Set the slave delay to 30 seconds to be able to see the 'waiting' message.
|
||||
diag("Setting slave delay to 0 seconds");
|
||||
$slave_dbh->do('STOP SLAVE');
|
||||
$slave_dbh->do('RESET SLAVE');
|
||||
$slave_dbh->do('START SLAVE');
|
||||
|
||||
diag('Loading test data');
|
||||
$sb->load_file('master', "t/pt-online-schema-change/samples/pt-1898.sql");
|
||||
|
||||
my $num_rows = 5000;
|
||||
diag("Loading $num_rows into the table. This might take some time.");
|
||||
diag(`util/mysql_random_data_load --host=127.0.0.1 --port=12345 --user=msandbox --password=msandbox test pt178 $num_rows`);
|
||||
|
||||
diag("Setting slave delay to $delay seconds");
|
||||
|
||||
$slave_dbh->do('STOP SLAVE');
|
||||
$slave_dbh->do("CHANGE MASTER TO MASTER_DELAY=$delay");
|
||||
$slave_dbh->do('START SLAVE');
|
||||
|
||||
# Run a full table scan query to ensure the slave is behind the master
|
||||
# There is no query cache in MySQL 8.0+
|
||||
reset_query_cache($master_dbh, $master_dbh);
|
||||
$master_dbh->do('UPDATE `test`.`joinit` SET g = g + 1 WHERE g <> 0');
|
||||
|
||||
# This is the base test, ust to ensure that without using --check-slave-lag nor --skip-check-slave-lag
|
||||
# pt-online-schema-change will wait on the slave at port 12346
|
||||
|
||||
my $max_lag = $delay / 2;
|
||||
my @args = ("--source", "$master_dsn,D=test,t=joinit", "--purge", "--where", "'g < 45'",
|
||||
"--commit-each", "--limit", "500", "--statistics", "--check-slave-lag", "h=127.0.0.1,P=12346,u=msandbox,p=msandbox",
|
||||
"--max-lag", "1");
|
||||
diag("Starting base test. This is going to take some time due to the delay in the slave");
|
||||
diag("pid: $tmp_file_name");
|
||||
my $argstr = join(@args, " ");
|
||||
my $output = `$trunk/bin/pt-online-schema-change $argstr 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Replica lag is \d+ seconds on .* Waiting/s,
|
||||
"Base test waits on the correct slave",
|
||||
);
|
||||
|
||||
|
||||
diag("Setting slave delay to 0 seconds");
|
||||
$slave_dbh->do('STOP SLAVE');
|
||||
$slave_dbh->do('RESET SLAVE');
|
||||
$slave_dbh->do('START SLAVE');
|
||||
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS test");
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
@@ -1,36 +0,0 @@
|
||||
-- give master some advantage on performance
|
||||
SET GLOBAL innodb_flush_log_at_trx_commit=2;
|
||||
SET GLOBAL sync_binlog=1000000;
|
||||
SET GLOBAL innodb_buffer_pool_size=2*1024*1024*1024;
|
||||
|
||||
DROP DATABASE IF EXISTS test;
|
||||
CREATE DATABASE test;.
|
||||
USE test;
|
||||
|
||||
DROP TABLE IF EXISTS `joinit`;
|
||||
|
||||
CREATE TABLE `joinit` (
|
||||
`i` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`s` varchar(64) DEFAULT NULL,
|
||||
`t` time NOT NULL,
|
||||
`g` int(11) NOT NULL,
|
||||
PRIMARY KEY (`i`),
|
||||
KEY g_idx (g)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
INSERT INTO joinit VALUES (NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )));
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit; -- +256 rows
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit; -- +512 rows
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit; -- +1024 rows
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
||||
INSERT INTO joinit SELECT NULL, uuid(), time(now()), (FLOOR( 1 + RAND( ) *60 )) FROM joinit;
|
Reference in New Issue
Block a user