1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#!/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-deadlock-logger";
use Data::Dumper;
# #############################################################################
# https://bugs.launchpad.net/percona-toolkit/+bug/903443
# pt-deadlock-logger crashes on MySQL 5.5
# #############################################################################
my $innodb_status_sample = load_file("t/pt-deadlock-logger/samples/bug_903443.txt");
is_deeply(
pt_deadlock_logger::parse_deadlocks($innodb_status_sample),
{
'1' => {
db => 'test',
hostname => 'localhost',
id => 1,
idx => 'PRIMARY',
ip => '',
lock_mode => 'X',
lock_type => 'RECORD',
query => 'update a set movie_id=96 where id =2',
server => '',
tbl => 'a',
thread => '19',
ts => '2011-12-12T22:52:42',
txn_id => 0,
txn_time => '161',
user => 'root',
victim => 0,
wait_hold => 'w'
},
'2' => {
db => 'test',
hostname => 'localhost',
id => 2,
idx => 'PRIMARY',
ip => '',
lock_mode => 'X',
lock_type => 'RECORD',
query => 'update a set movie_id=98 where id =4',
server => '',
tbl => 'a',
thread => '18',
ts => '2011-12-12T22:52:42',
txn_id => 0,
txn_time => '1026',
user => 'root',
victim => 1,
wait_hold => 'w'
}
},
"Bug 903443: pt-deadlock-logger parses the thread id incorrectly for MySQL 5.5",
);
# #############################################################################
# https://bugs.launchpad.net/percona-toolkit/+bug/1082104
# pt-deadlock-logger problem when the user have a dash in the name
# #############################################################################
$innodb_status_sample = load_file("t/pt-deadlock-logger/samples/bug_1082104.txt");
is_deeply(
pt_deadlock_logger::parse_deadlocks($innodb_status_sample),
{
'1' => {
db => 'test',
hostname => 'localhost',
id => 1,
idx => 'PRIMARY',
ip => '',
lock_mode => 'X',
lock_type => 'RECORD',
query => 'update a set movie_id=96 where id =2',
server => '',
tbl => 'a',
thread => '19',
ts => '2011-12-12T22:52:42',
txn_id => 0,
txn_time => '161',
user => 'ro-ot',
victim => 0,
wait_hold => 'w'
},
'2' => {
db => 'test',
hostname => 'localhost',
id => 2,
idx => 'PRIMARY',
ip => '',
lock_mode => 'X',
lock_type => 'RECORD',
query => 'update a set movie_id=98 where id =4',
server => '',
tbl => 'a',
thread => '18',
ts => '2011-12-12T22:52:42',
txn_id => 0,
txn_time => '1026',
user => 'ro-ot',
victim => 1,
wait_hold => 'w'
}
},
"Bug 1082104: pt-deadlock-logger shows host as user when the username has a dash in the name",
);
# #############################################################################
# https://bugs.launchpad.net/percona-toolkit/+bug/1195034
# pt-deadlock-logger error: Use of uninitialized value $ts in pattern match
# #############################################################################
$innodb_status_sample = load_file("t/pt-deadlock-logger/samples/bug_1195034.txt");
my $deadlocks = pt_deadlock_logger::parse_deadlocks($innodb_status_sample);
is_deeply(
$deadlocks,
{
},
"Bug 1195034: TOO DEEP OR LONG SEARCH IN THE LOCK TABLE WAITS-FOR GRAPH"
) or diag(Dumper($deadlocks));
# #############################################################################
# pt-deadlock-logger 2.2 requires a DSN
# https://bugs.launchpad.net/percona-toolkit/+bug/1206728
# #############################################################################
my $config = "/tmp/pt-deadlock-logger-test.conf.$PID";
`cp $trunk/t/pt-deadlock-logger/samples/pt-deadlock-logger-test.conf $config`;
my $output = `$trunk/bin/pt-deadlock-logger --config $config --iteration 1 2>&1`;
is(
$CHILD_ERROR,
0,
"Does not require explicit DSN (bug 1206728)"
) or diag($output);
diag(`rm -rf $config`);
# #############################################################################
# Done.
# #############################################################################
done_testing;
|