From bacccfd431f4e8706de2bd982e5f551072e65661 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 1 Feb 2012 11:27:18 -0700 Subject: [PATCH] Fix pt-query-digest tests. --- t/pt-query-digest/daemon.t | 2 +- t/pt-query-digest/mirror.t | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/t/pt-query-digest/daemon.t b/t/pt-query-digest/daemon.t index bf03713b..2261c963 100644 --- a/t/pt-query-digest/daemon.t +++ b/t/pt-query-digest/daemon.t @@ -41,7 +41,7 @@ SKIP: { 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"; `$cmd`; - $output = `ps -eaf | grep -v grep | grep pt-query-digest`; + $output = `ps x | grep 'pt-query-digest --daemonize --pid' | grep -v grep`; like($output, qr/$cmd/, 'It is running'); ok(-f '/tmp/pt-query-digest.pid', 'PID file created'); diff --git a/t/pt-query-digest/mirror.t b/t/pt-query-digest/mirror.t index 0db20e0e..1effcf4d 100644 --- a/t/pt-query-digest/mirror.t +++ b/t/pt-query-digest/mirror.t @@ -32,6 +32,9 @@ else { my $output; my $cmd; +my $pid_file = "/tmp/pt-query-digest-mirror-test.pid"; + +diag(`rm $pid_file 2>/dev/null`); # ########################################################################## # Tests for swapping --processlist and --execute @@ -41,12 +44,7 @@ $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{PTDEBUG}=1; `$cmd > /tmp/read_only.txt 2>&1 &`; @@ -58,15 +56,12 @@ $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; +chomp($output = `cat $pid_file`); +kill 15, $output; sleep 1; # 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 -p $output`; +unlike($output, qr/pt-query-digest/, 'It is stopped now'); $dbh1->do('set global read_only=0'); $dbh2->do('set global read_only=1'); @@ -95,6 +90,7 @@ diag(`rm -rf /tmp/read_only.txt`); # ############################################################################# # Done. # ############################################################################# +diag(`rm $pid_file 2>/dev/null`); $dbh1->do('set global read_only=0'); $dbh2->do('set global read_only=1'); $sb->wipe_clean($dbh1);