Merge lp:~percona-toolkit-dev/percona-toolkit/stabilize-test-suite r130.

This commit is contained in:
Daniel Nichter
2012-02-27 17:08:15 -07:00
39 changed files with 484 additions and 337 deletions

View File

@@ -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 x | grep 'pt-query-digest --daemonize --pid' | grep -v grep`;
$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;

View File

@@ -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'
);

View File

@@ -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;
@@ -36,6 +37,9 @@ my $pid_file = "/tmp/pt-query-digest-mirror-test.pid";
diag(`rm $pid_file 2>/dev/null`);
my $pid_file = '/tmp/pt-query-digest.test.pid';
`rm -rf $pid_file >/dev/null`;
# ##########################################################################
# Tests for swapping --processlist and --execute
# ##########################################################################
@@ -48,23 +52,33 @@ $cmd = "$trunk/bin/pt-query-digest "
$ENV{PTDEBUG}=1;
`$cmd > /tmp/read_only.txt 2>&1 &`;
$ENV{PTDEBUG}=0;
sleep 5;
$ENV{MKDEBUG}=0;
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;
chomp($output = `cat $pid_file`);
kill 15, $output;
sleep 1;
chomp(my $pid = `cat $pid_file`);
kill 15, $pid;
sleep 0.25;
# Verify that it's dead...
$output = `ps x | grep '^[ ]*$pid'`;
is(
$output,
'',
'It is stopped now'
);
=======
$output = `ps -p $output`;
unlike($output, qr/pt-query-digest/, 'It is stopped now');
>>>>>>> MERGE-SOURCE
$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)

View File

@@ -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,

View File

@@ -10,7 +10,7 @@
# Query_time distribution
# 1us
# 10us
# 100us ################################################################
# 100us
# 1ms
# 10ms
# 100ms