Files
percona-toolkit/t/pt-kill/match.t
Sveta Smirnova 25c969542b PT-2151 fix tests for pt-query-digest (#631)
* PT-2151 - Fix tests for pt-query-digest

Put fix for PT-1908 into the proper place

* PT-2151 - Fix tests for pt-query-digest

Put fix for PT-1554 into the proper place

* PT-2151 - Fix tests for pt-query-digest

Adjusted expected results for the default test t/pt-table-checksum/basics.t, so they do not depend on number of rows in the help tables

* PT-2151 - Fix tests for pt-query-digest

Added additional check for both replicas into t/pt-online-schema-change/preserve_triggers.t to avoid deadlock when ->ok() is doing CHECKSUM

* PT-2151 - Fix tests for pt-query-digest

Added delay to t/pt-table-sync/wait.t, so it waits for the child process to start lagging

* PT-2151 - Fix tests for pt-query-digest

Updated t/pt-query-digest/samples/issue_1196-output-8.0.txt, so it reflects changes in the latest 8.0

* PT-2151 - Fix tests for pt-query-digest

Updated queries against query history table, so they don't fail after e2cf183762

* PT-2151 - Fix tests for pt-query-digest

Fixed PT-813 by comparing query text. Since order itself does not matter, it is not essential to compare by the fingerprint or use any other function that changes the query.

* PT-2151 - Fix tests for pt-query-digest

Adjusted samples files which now should have consistent order after fix for PT-813

* PT-2151 - Fix tests for pt-query-digest

Fixed typo in the SELECT query in the QueryReview package

* PT-2151 - Fix tests for pt-query-digest

Fix for PT-981

* PT-2151 - Fix tests for pt-query-digest

Updated modules for pt-index-usage and fixed tests, because checksum is calculated differently after fix for PT-1554

* PT-2151 - Fix tests for pt-query-digest

Updated modules for pt-diskstats, pt-fk-error-logger, pt-heartbeat, pt-online-schema-change, pt-slave-delay, pt-slave-find, pt-table-checksum, pt-table-sync, pt-upgrade

* PT-2151 - Fix tests for pt-query-digest

Updated lib/IndexUsage.pm, so fix for pt-index-usage is in the correct place
2023-06-23 15:48:21 +03:00

198 lines
5.6 KiB
Perl

#!/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 tests => 17;
use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-kill";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $slave_dbh = $sb->get_dbh_for('slave1');
my @args = qw(--test-matching);
my $output;
# #############################################################################
# Test match commands.
# #############################################################################
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset001.txt", qw(--match-info show --print)); }
);
like(
$output,
qr/KILL 9 \(Query 0 sec\) show processlist/,
'--match-info'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset002.txt", qw(--match-command Query --print)); }
);
is(
$output,
'',
'Ignore State=Locked by default'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset002.txt", qw(--match-command Query --ignore-state), "''", "--print"); }
);
like(
$output,
qr/KILL 2 \(Query 5 sec\) select \* from foo2/,
"Can override default ignore State=Locked with --ignore-state ''"
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset003.txt", "--match-state", "Sorting result", "--print"); }
);
like(
$output,
qr/KILL 29393378 \(Query 3 sec\)/,
'--match-state'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset003.txt", qw(--match-state Updating --print --victims all)); }
);
like(
$output,
qr/(?:(?:KILL 29393612.+KILL 29393640)|(?:KILL 29393640.+KILL 29393612))/s,
'--victims all'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset003.txt", qw(--ignore-user remote --match-command Query --print)); }
);
like(
$output,
qr/KILL 29393138/,
'--ignore-user'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset004.txt", qw(--busy-time 25 --print)); }
);
like(
$output,
qr/KILL 54595/,
'--busy-time'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset004.txt", qw(--busy-time 30 --print)); }
);
is(
$output,
'',
'--busy-time but no query is busy enough'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset005.txt", qw(--idle-time 15 --print)); }
);
like(
$output,
qr/KILL 29392005 \(Sleep 17 sec\) NULL/,
'--idle-time'
);
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset006.txt", qw(--match-state Locked --ignore-state), "''", qw(--busy-time 5 --print)); }
);
like(
$output,
qr/KILL 2 \(Query 9 sec\) select \* from foo2/,
"--match-state Locked --ignore-state '' --busy-time 5"
);
# The queries in recset002 are both State: Locked which is ignored
# by default so nothing should match, not even for --match-all.
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset002.txt",
qw(--match-all --print)); }
);
is(
$output,
'',
"--match-all except ignored"
);
# Now --match-all should match.
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset002.txt",
qw(--match-all --victims all --print --ignore-state blahblah)); }
);
like(
$output,
qr/(?:(?:KILL 1.+KILL 2)|(?:KILL 2.+KILL 1))/s,
"--match-all"
);
# --query-id option
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset011.txt", qw(--match-all --print --query-id)); }
);
like(
$output,
qr/0x877B0CFF7AD32CA969962191E64980E6/,
'--query-id'
);
# --json option
$output = output(
sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset011.txt", qw(--match-all --print --json --json-fields key:value)); }
);
like(
$output,
qr/\{"Command"\:"Query","Db"\:"db","Digest"\:"877B0CFF7AD32CA969962191E64980E6","Host"\:"127\.0\.0\.1\:3306","Id"\:"4","Info"\:"\\\/\* fruit\=orange \*\\\/ select 1 from fuits;","Kill_Error"\:"","Reason"\:"","State"\:"statistics","Time"\:"6","Timestamp"\:".*","User"\:"foo","key"\:"value"\}/,
'--json'
);
# #############################################################################
# Live tests.
# #############################################################################
SKIP: {
skip "Cannot connect to sandbox slave", 1 unless $slave_dbh;
my $pl = $slave_dbh->selectall_arrayref('show processlist');
my @repl_thds = map { $_->[0] } grep { $_->[1] eq 'system user' } @$pl;
skip "Sandbox slave has no replication threads", unless scalar @repl_thds;
my $repl_thd_ids = join("|", @repl_thds);
$output = output(
sub { pt_kill::main(qw(-F /tmp/12346/my.sandbox.cnf --match-user system --print --run-time 1 --interval 1)); }
);
is(
$output,
'',
"Doesn't match replication threads by default"
);
$output = output(
sub { pt_kill::main(qw(-F /tmp/12346/my.sandbox.cnf --match-user system --print --replication-threads --run-time 1 --interval 1)); }
);
like(
$output,
qr/KILL (?:$repl_thd_ids)/,
"--replication-threads allows matching replication thread"
);
$slave_dbh->disconnect();
};
# #############################################################################
# Done.
# #############################################################################
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;