mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-09 18:30:16 +00:00
Various test tweaks for stability.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
err() {
|
||||
echo
|
||||
for msg; do
|
||||
echo "$msg"
|
||||
echo "$msg" >&2
|
||||
done
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Time::HiRes qw(sleep);
|
||||
use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
@@ -44,6 +45,7 @@ $sb->load_file('master', 't/pt-fk-error-logger/samples/fke_tbl.sql', 'test');
|
||||
|
||||
# Then get and save that fke.
|
||||
output(sub { pt_fk_error_logger::main('h=127.1,P=12345,u=msandbox,p=msandbox', '--dest', 'h=127.1,P=12345,D=test,t=foreign_key_errors'); } );
|
||||
sleep 0.1;
|
||||
|
||||
# And then test that it was actually saved.
|
||||
my $today = $dbh->selectall_arrayref('SELECT NOW()')->[0]->[0];
|
||||
@@ -64,6 +66,7 @@ like(
|
||||
# Check again to make sure that the same fke isn't saved twice.
|
||||
my $first_ts = $fke->[0]->[0];
|
||||
output(sub { pt_fk_error_logger::main('h=127.1,P=12345,u=msandbox,p=msandbox', '--dest', 'h=127.1,P=12345,D=test,t=foreign_key_errors'); } );
|
||||
sleep 0.1;
|
||||
$fke = $dbh->selectall_arrayref('SELECT * FROM test.foreign_key_errors');
|
||||
is(
|
||||
$fke->[0]->[0], # Timestamp
|
||||
@@ -84,6 +87,7 @@ eval {
|
||||
$dbh->do('DELETE FROM parent WHERE id = 2'); # Causes foreign key error.
|
||||
};
|
||||
output( sub { pt_fk_error_logger::main('h=127.1,P=12345,u=msandbox,p=msandbox', '--dest', 'h=127.1,P=12345,D=test,t=foreign_key_errors'); } );
|
||||
sleep 0.1;
|
||||
$fke = $dbh->selectall_arrayref('SELECT * FROM test.foreign_key_errors');
|
||||
like(
|
||||
$fke->[1]->[1], # Error
|
||||
@@ -99,7 +103,6 @@ is(
|
||||
# ##########################################################################
|
||||
# Test printing the errors.
|
||||
# ##########################################################################
|
||||
sleep 1;
|
||||
$dbh->do('USE test');
|
||||
eval {
|
||||
$dbh->do('DELETE FROM parent WHERE id = 2'); # Causes foreign key error.
|
||||
|
@@ -32,9 +32,10 @@ my $output;
|
||||
my $cnf = '/tmp/12345/my.sandbox.cnf';
|
||||
my $cmd = "$trunk/bin/pt-heartbeat -F $cnf ";
|
||||
my $pid_file = "/tmp/__pt-heartbeat-test.pid";
|
||||
my $sent_file = "/tmp/pt-heartbeat-sentinel";
|
||||
my $ps_grep_cmd = "ps x | grep pt-heartbeat | grep daemonize | grep -v grep";
|
||||
|
||||
`rm /tmp/pt-heartbeat-sentinel 2>/dev/null`;
|
||||
`rm $sent_file 2>/dev/null`;
|
||||
|
||||
$dbh->do('drop table if exists test.heartbeat');
|
||||
$dbh->do(q{CREATE TABLE test.heartbeat (
|
||||
@@ -102,8 +103,8 @@ like($output, qr/Successfully created/, 'Created sentinel');
|
||||
sleep(2);
|
||||
$output = `$ps_grep_cmd`;
|
||||
unlike($output, qr/$cmd/, 'It is not running');
|
||||
ok(-f '/tmp/pt-heartbeat-sentinel', 'Sentinel file is there');
|
||||
unlink('/tmp/pt-heartbeat-sentinel');
|
||||
ok(-f $sent_file, 'Sentinel file is there');
|
||||
unlink($sent_file);
|
||||
$dbh->do('drop table if exists test.heartbeat'); # This will kill it
|
||||
|
||||
# #############################################################################
|
||||
@@ -137,5 +138,6 @@ like(
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
`rm $pid_file $sent_file 2>/dev/null`;
|
||||
$sb->wipe_clean($dbh);
|
||||
exit;
|
||||
|
@@ -116,24 +116,33 @@ is_deeply(
|
||||
"Table access counts"
|
||||
);
|
||||
|
||||
# EXPLAIN results differ a little between 5.0 and 5.1. 5.1 is smarter.
|
||||
my $res = $sandbox_version ge '5.1' ?
|
||||
# v5.1 and newer
|
||||
[
|
||||
$rows = $dbh->selectall_arrayref("select * from mk.indexes order by db, tbl");
|
||||
# EXPLAIN results differ a little between 5.0 and 5.1, and sometimes 5.1 acts
|
||||
# like 5.0. So here we detect which verison MySQL is acting like and future
|
||||
# tests will select between 2 possibilities based on exp_plan. Note: both
|
||||
# possibilities are correct; they're variants of the same result.
|
||||
my $res;
|
||||
my $exp_plan;
|
||||
if ( $rows->[0]->[3] == 1 ) {
|
||||
# Usually v5.1 and newer
|
||||
$res = [
|
||||
[qw(sakila actor idx_actor_last_name 1)],
|
||||
[qw(sakila actor PRIMARY 3)],
|
||||
[qw(sakila address idx_fk_city_id 0)],
|
||||
[qw(sakila address PRIMARY 0)],
|
||||
]
|
||||
: # v5.0 and older
|
||||
[
|
||||
];
|
||||
$exp_plan = '5.1'; # acting like 5.1
|
||||
}
|
||||
else {
|
||||
# Usually v5.0 and older, but somtimes 5.1.
|
||||
$res = [
|
||||
[qw(sakila actor idx_actor_last_name 2)],
|
||||
[qw(sakila actor PRIMARY 2)],
|
||||
[qw(sakila address idx_fk_city_id 0)],
|
||||
[qw(sakila address PRIMARY 0)],
|
||||
];
|
||||
|
||||
$rows = $dbh->selectall_arrayref("select * from mk.indexes order by db, tbl");
|
||||
$exp_plan = '5.0'; # acting like 5.0
|
||||
}
|
||||
is_deeply(
|
||||
$rows,
|
||||
$res,
|
||||
@@ -161,7 +170,7 @@ is_deeply(
|
||||
);
|
||||
|
||||
$rows = $dbh->selectall_arrayref("select query_id, db, tbl, idx, sample, cnt from index_usage iu left join queries q using (query_id) order by db, tbl, idx");
|
||||
$res = $sandbox_version ge '5.1' ?
|
||||
$res = $exp_plan eq '5.1' ?
|
||||
# v5.1 and newer
|
||||
[
|
||||
[
|
||||
@@ -212,7 +221,7 @@ is_deeply(
|
||||
);
|
||||
|
||||
$rows = $dbh->selectall_arrayref("select db,tbl,idx,alt_idx,sample from index_alternatives a left join queries q using (query_id)");
|
||||
$res = $sandbox_version ge '5.1' ?
|
||||
$res = $exp_plan eq '5.1' ?
|
||||
[[qw(sakila actor PRIMARY idx_actor_last_name),
|
||||
"select * from sakila.actor where last_name like 'A%' order by actor_id"]]
|
||||
: [];
|
||||
@@ -239,7 +248,7 @@ is_deeply(
|
||||
);
|
||||
|
||||
# EXPLAIN results differ a little between 5.0 and 5.1. 5.1 is smarter.
|
||||
$res = $sandbox_version ge '5.1' ?
|
||||
$res = $exp_plan eq '5.1' ?
|
||||
# v5.1 and newer
|
||||
[
|
||||
[qw(sakila actor idx_actor_last_name 2)],
|
||||
@@ -283,7 +292,7 @@ is_deeply(
|
||||
);
|
||||
|
||||
$rows = $dbh->selectall_arrayref("select query_id, db, tbl, idx, sample, cnt from index_usage iu left join queries q using (query_id) order by db, tbl, idx");
|
||||
$res = $sandbox_version ge '5.1' ?
|
||||
$res = $exp_plan eq '5.1' ?
|
||||
# v5.1 and newer
|
||||
[
|
||||
[
|
||||
@@ -334,7 +343,7 @@ is_deeply(
|
||||
);
|
||||
|
||||
$rows = $dbh->selectall_arrayref("select db,tbl,idx,alt_idx,sample from index_alternatives a left join queries q using (query_id)");
|
||||
$res = $sandbox_version ge '5.1' ?
|
||||
$res = $exp_plan eq '5.1' ?
|
||||
[[qw(sakila actor PRIMARY idx_actor_last_name),
|
||||
"select * from sakila.actor where last_name like 'A%' order by actor_id"]]
|
||||
: [];
|
||||
|
@@ -116,7 +116,7 @@ is(
|
||||
# #############################################################################
|
||||
# No --alter and --drop-old-table.
|
||||
# #############################################################################
|
||||
$dbh->do('drop table mkosc.__old_a'); # from previous run
|
||||
$dbh->do('drop table if exists mkosc.__old_a'); # from previous run
|
||||
$sb->load_file('master', "t/pt-online-schema-change/samples/small_table.sql");
|
||||
|
||||
output(
|
||||
|
@@ -9,6 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Time::HiRes qw(sleep);
|
||||
use Test::More tests => 6;
|
||||
|
||||
use PerconaTest;
|
||||
@@ -21,17 +22,20 @@ my $dbh = $sb->get_dbh_for('master');
|
||||
|
||||
my $output;
|
||||
|
||||
my $pid_file = '/tmp/pt-query-digest.test.pid';
|
||||
`rm $pid_file >/dev/null 2>&1`;
|
||||
|
||||
# #########################################################################
|
||||
# Issue 391: Add --pid option to all scripts
|
||||
# #########################################################################
|
||||
`touch /tmp/pt-script.pid`;
|
||||
$output = `$trunk/bin/pt-query-digest $trunk/commont/t/samples/slow002.txt --pid /tmp/pt-script.pid 2>&1`;
|
||||
`touch $pid_file`;
|
||||
$output = `$trunk/bin/pt-query-digest $trunk/commont/t/samples/slow002.txt --pid $pid_file 2>&1`;
|
||||
like(
|
||||
$output,
|
||||
qr{PID file /tmp/pt-script.pid already exists},
|
||||
qr{PID file $pid_file already exists},
|
||||
'Dies if PID file already exists (--pid without --daemonize) (issue 391)'
|
||||
);
|
||||
`rm -rf /tmp/pt-script.pid`;
|
||||
`rm $pid_file >/dev/null 2>&1`;
|
||||
|
||||
# #########################################################################
|
||||
# Daemonizing and pid creation
|
||||
@@ -39,22 +43,22 @@ like(
|
||||
SKIP: {
|
||||
skip "Cannot connect to sandbox master", 5 unless $dbh;
|
||||
|
||||
my $cmd = "$trunk/bin/pt-query-digest --daemonize --pid /tmp/pt-query-digest.pid --processlist h=127.1,P=12345,u=msandbox,p=msandbox --log /dev/null";
|
||||
my $cmd = "$trunk/bin/pt-query-digest --daemonize --pid $pid_file --processlist h=127.1,P=12345,u=msandbox,p=msandbox --log /dev/null";
|
||||
`$cmd`;
|
||||
$output = `ps -eaf | grep -v grep | grep pt-query-digest`;
|
||||
$output = `ps xw | grep -v grep | grep '$cmd'`;
|
||||
like($output, qr/$cmd/, 'It is running');
|
||||
ok(-f '/tmp/pt-query-digest.pid', 'PID file created');
|
||||
ok(-f $pid_file, 'PID file created');
|
||||
|
||||
my ($pid) = $output =~ /\s+(\d+)\s+/;
|
||||
$output = `cat /tmp/pt-query-digest.pid`;
|
||||
my ($pid) = $output =~ /^\s*(\d+)/;
|
||||
chomp($output = `cat $pid_file`);
|
||||
is($output, $pid, 'PID file has correct PID');
|
||||
|
||||
kill 15, $pid;
|
||||
sleep 1;
|
||||
$output = `ps -eaf | grep pt-query-digest | grep daemonize`;
|
||||
unlike($output, qr/$trunk\/pt-query-digest\/pt-query-digest/, 'It is not running');
|
||||
sleep 0.25;
|
||||
$output = `ps xw | grep -v grep | grep '$cmd'`;
|
||||
is($output, "", 'It is not running');
|
||||
ok(
|
||||
!-f '/tmp/pt-query-digest.pid',
|
||||
!-f $pid_file,
|
||||
'Removes its PID file'
|
||||
);
|
||||
};
|
||||
@@ -62,4 +66,5 @@ SKIP: {
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
`rm $pid_file >/dev/null 2>&1`;
|
||||
exit;
|
||||
|
@@ -68,6 +68,8 @@ $cnf .= ',D=test';
|
||||
# TODO: This test is a PITA because every time the mqd output
|
||||
# changes the -n of tail has to be adjusted.
|
||||
|
||||
#
|
||||
|
||||
# We tail to get everything from "Exec orig" onward. The lines
|
||||
# above have the real execution time will will vary. The last 18 lines
|
||||
# are sufficient to see that it actually executed without errors.
|
||||
@@ -77,6 +79,7 @@ ok(
|
||||
"$trunk/t/lib/samples/slowlogs/slow018.txt") },
|
||||
't/pt-query-digest/samples/slow018_execute_report_2.txt',
|
||||
trf => 'tail -n 30',
|
||||
sed => ["-e 's/s ##*/s/g'"],
|
||||
),
|
||||
'--execute with default database'
|
||||
);
|
||||
|
@@ -10,6 +10,7 @@ use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use Time::HiRes qw(sleep);
|
||||
|
||||
use PerconaTest;
|
||||
use DSNParser;
|
||||
@@ -33,6 +34,9 @@ else {
|
||||
my $output;
|
||||
my $cmd;
|
||||
|
||||
my $pid_file = '/tmp/pt-query-digest.test.pid';
|
||||
`rm -rf $pid_file >/dev/null`;
|
||||
|
||||
# ##########################################################################
|
||||
# Tests for swapping --processlist and --execute
|
||||
# ##########################################################################
|
||||
@@ -41,35 +45,29 @@ $dbh2->do('set global read_only=1');
|
||||
$cmd = "$trunk/bin/pt-query-digest "
|
||||
. "--processlist h=127.1,P=12345,u=msandbox,p=msandbox "
|
||||
. "--execute h=127.1,P=12346,u=msandbox,p=msandbox --mirror 1 "
|
||||
. "--pid foobar";
|
||||
# --pid actually does nothing because the script is not daemonizing.
|
||||
# I include it for the identifier (foobar) so that we can more easily
|
||||
# grep the PID below. Otherwise, a ps | grep mk-query-digest will
|
||||
# match this test script and any vi mk-query-digest[.t] that may happen
|
||||
# to be running.
|
||||
. "--pid $pid_file";
|
||||
|
||||
$ENV{MKDEBUG}=1;
|
||||
`$cmd > /tmp/read_only.txt 2>&1 &`;
|
||||
$ENV{MKDEBUG}=0;
|
||||
sleep 5;
|
||||
sleep 3;
|
||||
$dbh1->do('select sleep(1)');
|
||||
sleep 1;
|
||||
$dbh1->do('set global read_only=1');
|
||||
$dbh2->do('set global read_only=0');
|
||||
$dbh1->do('select sleep(1)');
|
||||
sleep 2;
|
||||
$output = `ps -eaf | grep mk-query-diges[t] | grep foobar | awk '{print \$2}'`;
|
||||
kill 15, $output =~ m/(\d+)/g;
|
||||
sleep 1;
|
||||
chomp(my $pid = `cat $pid_file`);
|
||||
kill 15, $pid;
|
||||
sleep 0.25;
|
||||
# Verify that it's dead...
|
||||
$output = `ps -eaf | grep mk-query-diges[t] | grep foobar`;
|
||||
if ( $output =~ m/digest/ ) {
|
||||
$output = `ps -eaf | grep mk-query-diges[t] | grep foobar`;
|
||||
}
|
||||
unlike($output, qr/mk-query-digest/, 'It is stopped now');
|
||||
$output = `ps x | grep '^[ ]*$pid'`;
|
||||
is(
|
||||
$output,
|
||||
'',
|
||||
'It is stopped now'
|
||||
);
|
||||
|
||||
$dbh1->do('set global read_only=0');
|
||||
$dbh2->do('set global read_only=1');
|
||||
$output = `grep read_only /tmp/read_only.txt`;
|
||||
# Sample output:
|
||||
# # main:3619 6897 read_only on execute for --execute: 1 (want 1)
|
||||
|
@@ -55,6 +55,12 @@ my $output = output(
|
||||
);
|
||||
|
||||
($exec) = $output =~ m/^(# Exec time.+?)$/ms;
|
||||
# The end of the line is like "786ms 3s". The 2nd to last value is
|
||||
# stddev which can vary slightly depending on the real exec time. The
|
||||
# other int values should always round to the correct values. 786ms is
|
||||
# the usual stddev. -- stddev doesn't matter much. It's the other vals
|
||||
# that indicate that --processlist works.
|
||||
$exec =~ s/(\S+) 3s$/786ms 3s/;
|
||||
ok(
|
||||
no_diff(
|
||||
$exec,
|
||||
|
@@ -10,7 +10,7 @@
|
||||
# Query_time distribution
|
||||
# 1us
|
||||
# 10us
|
||||
# 100us ################################################################
|
||||
# 100us
|
||||
# 1ms
|
||||
# 10ms
|
||||
# 100ms
|
||||
|
Reference in New Issue
Block a user