Merge lp:~percona-toolkit-dev/percona-toolkit/fix-daemon-tests into lp:~percona-toolkit-dev/percona-toolkit/fix-pt-archiver-dry-run-bug-1199589

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 601
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-daemon-tests
Merge into: lp:~percona-toolkit-dev/percona-toolkit/fix-pt-archiver-dry-run-bug-1199589
Diff against target: 245 lines (+77/-55)
3 files modified
lib/PerconaTest.pm (+14/-0)
t/lib/Daemon.t (+58/-52)
t/pt-stalk/pt-stalk.t (+5/-3)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-daemon-tests
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+179591@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/PerconaTest.pm'
--- lib/PerconaTest.pm 2013-03-21 19:50:49 +0000
+++ lib/PerconaTest.pm 2013-08-11 02:43:48 +0000
@@ -819,6 +819,20 @@
819 return [ sort keys %tables ];819 return [ sort keys %tables ];
820}820}
821821
822sub get_cmd_pid {
823 my $cmd = shift;
824 $cmd =~ s/\./\\./g;
825 $cmd =~ s/-/\\-/g;
826 my $output = `ps xww | grep -v grep | grep '$cmd'`;
827 my @cmds = $output =~ m/\n/g;
828 if ( @cmds > 1 ) {
829 die "Found " . scalar @cmds . " commands matching '$cmd': @cmds";
830 }
831 my ($pid) = $output =~ m/^\s*(\d+)/;
832 return wantarray ? ($pid, $output) : $pid;
833}
834
835
822sub can_load_data {836sub can_load_data {
823 my $output = `/tmp/12345/use -e "SELECT * FROM percona_test.load_data" 2>/dev/null`;837 my $output = `/tmp/12345/use -e "SELECT * FROM percona_test.load_data" 2>/dev/null`;
824 return ($output || '') =~ /1/;838 return ($output || '') =~ /1/;
825839
=== modified file 't/lib/Daemon.t'
--- t/lib/Daemon.t 2013-04-05 18:16:16 +0000
+++ t/lib/Daemon.t 2013-08-11 02:43:48 +0000
@@ -31,13 +31,14 @@
31# Test that it daemonizes, creates a PID file, and removes that PID file.31# Test that it daemonizes, creates a PID file, and removes that PID file.
32# ############################################################################32# ############################################################################
3333
34my $ret_val = system("$cmd 5 --daemonize --pid $pid_file >/dev/null 2>&1");34my $ret_val = system("$cmd 3 --daemonize --pid $pid_file --log $log_file");
35die 'Cannot test Daemon.pm because t/daemonizes.pl is not working'35die 'Cannot test Daemon.pm because t/daemonizes.pl is not working'
36 unless $ret_val == 0;36 unless $ret_val == 0;
3737
38PerconaTest::wait_for_files($pid_file);38PerconaTest::wait_for_files($pid_file, $log_file)
39 or die "$cmd did not create $pid_file and $log_file";
3940
40my $output = `ps wx | grep '$cmd 5' | grep -v grep`;41my ($pid, $output) = PerconaTest::get_cmd_pid("$cmd 3");
4142
42like(43like(
43 $output,44 $output,
@@ -50,7 +51,6 @@
50 'Creates PID file'51 'Creates PID file'
51);52);
5253
53my ($pid) = $output =~ /^\s*(\d+)\s+/;
54$output = slurp_file($pid_file);54$output = slurp_file($pid_file);
55chomp($output) if $output;55chomp($output) if $output;
5656
@@ -60,12 +60,16 @@
60 'PID file has correct PID'60 'PID file has correct PID'
61);61);
6262
63# Wait until the process goes away63SKIP: {
64PerconaTest::wait_until(sub { !kill(0, $pid) });64 skip "Previous tests failed", 1 unless $pid;
65ok(65
66 ! -f $pid_file,66 # Wait until the process goes away
67 'Removes PID file upon exit'67 PerconaTest::wait_until(sub { !kill(0, $pid) });
68);68 ok(
69 ! -f $pid_file,
70 'Removes PID file upon exit'
71 );
72}
6973
70# ############################################################################74# ############################################################################
71# Check that STDOUT can be redirected75# Check that STDOUT can be redirected
@@ -132,12 +136,14 @@
132# ##########################################################################136# ##########################################################################
133rm_tmp_files();137rm_tmp_files();
134SKIP: {138SKIP: {
135 skip 'No /proc', 2 unless -d '/proc';139 skip 'No /proc', 1 unless -d '/proc';
136 skip 'No fd in /proc', 2 unless -l "/proc/$PID/0" || -l "/proc/$PID/fd/0";140 skip 'No fd in /proc', 1 unless -l "/proc/$PID/0" || -l "/proc/$PID/fd/0";
137141
138 system("$cmd 5 --daemonize --pid $pid_file --log $log_file");142 system("$cmd 15 --daemonize --pid $pid_file --log $log_file");
139 PerconaTest::wait_for_files($pid_file);143 PerconaTest::wait_for_files($pid_file, $log_file)
140 chomp($pid = slurp_file($pid_file));144 or die "$cmd did not create $pid_file and $log_file";
145 my $pid = PerconaTest::get_cmd_pid("$cmd 15")
146 or die "Cannot get PID of $cmd 15\n" . `ps xww`;
141 my $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"147 my $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"
142 : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"148 : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
143 : die "Cannot find fd 0 symlink in /proc/$pid";149 : die "Cannot find fd 0 symlink in /proc/$pid";
@@ -150,38 +156,41 @@
150 'Reopens STDIN to /dev/null'156 'Reopens STDIN to /dev/null'
151 );157 );
152158
153 SKIP: {159 PerconaTest::kill_program(pid => $pid);
154 skip "-t is not reliable", 1;160
155 rm_tmp_files();161# SKIP: {
156 system("echo foo | $cmd 5 --daemonize --pid $pid_file --log $log_file");162# skip "-t is not reliable", 1;
157 PerconaTest::wait_for_files($pid_file, $log_file);163# rm_tmp_files();
158 chomp($pid = slurp_file($pid_file));164# system("echo foo | $cmd 5 --daemonize --pid $pid_file --log $log_file");
159 $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"165# PerconaTest::wait_for_files($pid_file, $log_file);
160 : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"166# chomp($pid = slurp_file($pid_file));
161 : die "Cannot find fd 0 symlink in /proc/$pid";167# $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"
162 PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file,168# : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
163 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`);169# : die "Cannot find fd 0 symlink in /proc/$pid";
164 $stdin = readlink $proc_fd_0;170# PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file,
165 like(171# 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`);
166 $stdin,172# $stdin = readlink $proc_fd_0;
167 qr/pipe/,173# like(
168 'Does not reopen STDIN to /dev/null when piped',174# $stdin,
169 );175# qr/pipe/,
170 rm_tmp_files();176# 'Does not reopen STDIN to /dev/null when piped',
171 }177# );
172};178# rm_tmp_files();
179# }
180}
173181
174# ##########################################################################182# ##########################################################################
175# Issue 419: Daemon should check wether process with pid obtained from183# Issue 419: Daemon should check wether process with pid obtained from
176# pid-file is still running184# pid-file is still running
177# ##########################################################################185# ##########################################################################
178rm_tmp_files();186rm_tmp_files();
179system("$cmd 5 --daemonize --pid $pid_file >/dev/null 2>&1");187system("$cmd 7 --daemonize --pid $pid_file >/dev/null 2>&1");
180PerconaTest::wait_for_files($pid_file);188PerconaTest::wait_for_files($pid_file);
181chomp($pid = slurp_file($pid_file));189$pid = PerconaTest::get_cmd_pid("$cmd 7")
190 or die "Cannot get PID of $cmd 7";
182kill 9, $pid;191kill 9, $pid;
183sleep 0.25;192sleep 0.25;
184$output = `ps wx | grep '^[ ]*$pid' | grep -v grep`;193(undef, $output) = PerconaTest::get_cmd_pid("$cmd 7");
185unlike(194unlike(
186 $output,195 $output,
187 qr/daemonize/,196 qr/daemonize/,
@@ -194,11 +203,10 @@
194203
195my (undef, $tempfile) = tempfile();204my (undef, $tempfile) = tempfile();
196205
197system("$cmd 5 --daemonize --log $log_file --pid $pid_file > $tempfile 2>&1");206system("$cmd 6 --daemonize --log $log_file --pid $pid_file > $tempfile 2>&1");
198PerconaTest::wait_for_files($log_file, $pid_file, $tempfile);207PerconaTest::wait_for_files($log_file, $pid_file, $tempfile);
199208my $new_pid;
200$output = `ps wx | grep '$cmd 5' | grep -v grep`;209($new_pid, $output) = PerconaTest::get_cmd_pid("$cmd 6");
201chomp(my $new_pid = slurp_file($pid_file));
202210
203like(211like(
204 $output,212 $output,
@@ -212,12 +220,14 @@
212 'Says that old PID is not running (issue 419)'220 'Says that old PID is not running (issue 419)'
213);221);
214222
215ok(223cmp_ok(
216 $pid != $new_pid,224 $pid,
225 '!=',
226 $new_pid,
217 'Overwrites PID file with new PID (issue 419)'227 'Overwrites PID file with new PID (issue 419)'
218);228);
219229
220PerconaTest::wait_until(sub { !-e $pid_file });230PerconaTest::wait_until(sub { !-f $pid_file });
221ok(231ok(
222 !-f $pid_file,232 !-f $pid_file,
223 'Re-used PID file still removed (issue 419)'233 'Re-used PID file still removed (issue 419)'
@@ -229,21 +239,17 @@
229# Check that it actually checks the running process.239# Check that it actually checks the running process.
230# ############################################################################240# ############################################################################
231rm_tmp_files();241rm_tmp_files();
232system("$cmd 20 --daemonize --log $log_file --pid $pid_file");242system("$cmd 10 --daemonize --log $log_file --pid $pid_file");
233PerconaTest::wait_for_files($pid_file, $log_file);243PerconaTest::wait_for_files($pid_file, $log_file);
234chomp($pid = slurp_file($pid_file));244chomp($pid = slurp_file($pid_file));
235$output = `$cmd 0 --daemonize --pid $pid_file 2>&1`;245$output = `$cmd 1 --daemonize --pid $pid_file 2>&1`;
236like(246like(
237 $output,247 $output,
238 qr/PID file $pid_file exists and PID $pid is running/,248 qr/PID file $pid_file exists and PID $pid is running/,
239 'Says that PID is running (issue 419)'249 'Says that PID is running (issue 419)'
240);250);
241251
242if ( $pid ) {252PerconaTest::kill_program(pid => $pid);
243 kill 9, $pid;
244}
245
246sleep 0.25;
247rm_tmp_files();253rm_tmp_files();
248254
249# #############################################################################255# #############################################################################
250256
=== modified file 't/pt-stalk/pt-stalk.t'
--- t/pt-stalk/pt-stalk.t 2013-04-08 13:13:56 +0000
+++ t/pt-stalk/pt-stalk.t 2013-08-11 02:43:48 +0000
@@ -79,9 +79,9 @@
79# As of v2.1.9 when --verbose was added, non-matching checks are not79# As of v2.1.9 when --verbose was added, non-matching checks are not
80# printed by default. So we use the --plugin to tell us when the tool80# printed by default. So we use the --plugin to tell us when the tool
81# has completed a cycle.81# has completed a cycle.
8282warn "1 before cmd";
83$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf");83$retval = system("/bin/bash -x $trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf");
8484warn "2 after cmd";
85is(85is(
86 $retval >> 8,86 $retval >> 8,
87 0,87 0,
@@ -143,6 +143,8 @@
143# #############################################################################143# #############################################################################
144144
145cleanup();145cleanup();
146done_testing;
147exit;
146148
147$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --variable Threads_running --dest $dest --verbose 3 -- --defaults-file=$cnf");149$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --variable Threads_running --dest $dest --verbose 3 -- --defaults-file=$cnf");
148150

Subscribers

People subscribed via source and target branches

to all changes: