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
1=== modified file 'lib/PerconaTest.pm'
2--- lib/PerconaTest.pm 2013-03-21 19:50:49 +0000
3+++ lib/PerconaTest.pm 2013-08-11 02:43:48 +0000
4@@ -819,6 +819,20 @@
5 return [ sort keys %tables ];
6 }
7
8+sub get_cmd_pid {
9+ my $cmd = shift;
10+ $cmd =~ s/\./\\./g;
11+ $cmd =~ s/-/\\-/g;
12+ my $output = `ps xww | grep -v grep | grep '$cmd'`;
13+ my @cmds = $output =~ m/\n/g;
14+ if ( @cmds > 1 ) {
15+ die "Found " . scalar @cmds . " commands matching '$cmd': @cmds";
16+ }
17+ my ($pid) = $output =~ m/^\s*(\d+)/;
18+ return wantarray ? ($pid, $output) : $pid;
19+}
20+
21+
22 sub can_load_data {
23 my $output = `/tmp/12345/use -e "SELECT * FROM percona_test.load_data" 2>/dev/null`;
24 return ($output || '') =~ /1/;
25
26=== modified file 't/lib/Daemon.t'
27--- t/lib/Daemon.t 2013-04-05 18:16:16 +0000
28+++ t/lib/Daemon.t 2013-08-11 02:43:48 +0000
29@@ -31,13 +31,14 @@
30 # Test that it daemonizes, creates a PID file, and removes that PID file.
31 # ############################################################################
32
33-my $ret_val = system("$cmd 5 --daemonize --pid $pid_file >/dev/null 2>&1");
34+my $ret_val = system("$cmd 3 --daemonize --pid $pid_file --log $log_file");
35 die 'Cannot test Daemon.pm because t/daemonizes.pl is not working'
36 unless $ret_val == 0;
37
38-PerconaTest::wait_for_files($pid_file);
39+PerconaTest::wait_for_files($pid_file, $log_file)
40+ or die "$cmd did not create $pid_file and $log_file";
41
42-my $output = `ps wx | grep '$cmd 5' | grep -v grep`;
43+my ($pid, $output) = PerconaTest::get_cmd_pid("$cmd 3");
44
45 like(
46 $output,
47@@ -50,7 +51,6 @@
48 'Creates PID file'
49 );
50
51-my ($pid) = $output =~ /^\s*(\d+)\s+/;
52 $output = slurp_file($pid_file);
53 chomp($output) if $output;
54
55@@ -60,12 +60,16 @@
56 'PID file has correct PID'
57 );
58
59-# Wait until the process goes away
60-PerconaTest::wait_until(sub { !kill(0, $pid) });
61-ok(
62- ! -f $pid_file,
63- 'Removes PID file upon exit'
64-);
65+SKIP: {
66+ skip "Previous tests failed", 1 unless $pid;
67+
68+ # Wait until the process goes away
69+ PerconaTest::wait_until(sub { !kill(0, $pid) });
70+ ok(
71+ ! -f $pid_file,
72+ 'Removes PID file upon exit'
73+ );
74+}
75
76 # ############################################################################
77 # Check that STDOUT can be redirected
78@@ -132,12 +136,14 @@
79 # ##########################################################################
80 rm_tmp_files();
81 SKIP: {
82- skip 'No /proc', 2 unless -d '/proc';
83- skip 'No fd in /proc', 2 unless -l "/proc/$PID/0" || -l "/proc/$PID/fd/0";
84+ skip 'No /proc', 1 unless -d '/proc';
85+ skip 'No fd in /proc', 1 unless -l "/proc/$PID/0" || -l "/proc/$PID/fd/0";
86
87- system("$cmd 5 --daemonize --pid $pid_file --log $log_file");
88- PerconaTest::wait_for_files($pid_file);
89- chomp($pid = slurp_file($pid_file));
90+ system("$cmd 15 --daemonize --pid $pid_file --log $log_file");
91+ PerconaTest::wait_for_files($pid_file, $log_file)
92+ or die "$cmd did not create $pid_file and $log_file";
93+ my $pid = PerconaTest::get_cmd_pid("$cmd 15")
94+ or die "Cannot get PID of $cmd 15\n" . `ps xww`;
95 my $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"
96 : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
97 : die "Cannot find fd 0 symlink in /proc/$pid";
98@@ -150,38 +156,41 @@
99 'Reopens STDIN to /dev/null'
100 );
101
102- SKIP: {
103- skip "-t is not reliable", 1;
104- rm_tmp_files();
105- system("echo foo | $cmd 5 --daemonize --pid $pid_file --log $log_file");
106- PerconaTest::wait_for_files($pid_file, $log_file);
107- chomp($pid = slurp_file($pid_file));
108- $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"
109- : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
110- : die "Cannot find fd 0 symlink in /proc/$pid";
111- PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file,
112- 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`);
113- $stdin = readlink $proc_fd_0;
114- like(
115- $stdin,
116- qr/pipe/,
117- 'Does not reopen STDIN to /dev/null when piped',
118- );
119- rm_tmp_files();
120- }
121-};
122+ PerconaTest::kill_program(pid => $pid);
123+
124+# SKIP: {
125+# skip "-t is not reliable", 1;
126+# rm_tmp_files();
127+# system("echo foo | $cmd 5 --daemonize --pid $pid_file --log $log_file");
128+# PerconaTest::wait_for_files($pid_file, $log_file);
129+# chomp($pid = slurp_file($pid_file));
130+# $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"
131+# : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
132+# : die "Cannot find fd 0 symlink in /proc/$pid";
133+# PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file,
134+# 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`);
135+# $stdin = readlink $proc_fd_0;
136+# like(
137+# $stdin,
138+# qr/pipe/,
139+# 'Does not reopen STDIN to /dev/null when piped',
140+# );
141+# rm_tmp_files();
142+# }
143+}
144
145 # ##########################################################################
146 # Issue 419: Daemon should check wether process with pid obtained from
147 # pid-file is still running
148 # ##########################################################################
149 rm_tmp_files();
150-system("$cmd 5 --daemonize --pid $pid_file >/dev/null 2>&1");
151+system("$cmd 7 --daemonize --pid $pid_file >/dev/null 2>&1");
152 PerconaTest::wait_for_files($pid_file);
153-chomp($pid = slurp_file($pid_file));
154+$pid = PerconaTest::get_cmd_pid("$cmd 7")
155+ or die "Cannot get PID of $cmd 7";
156 kill 9, $pid;
157 sleep 0.25;
158-$output = `ps wx | grep '^[ ]*$pid' | grep -v grep`;
159+(undef, $output) = PerconaTest::get_cmd_pid("$cmd 7");
160 unlike(
161 $output,
162 qr/daemonize/,
163@@ -194,11 +203,10 @@
164
165 my (undef, $tempfile) = tempfile();
166
167-system("$cmd 5 --daemonize --log $log_file --pid $pid_file > $tempfile 2>&1");
168+system("$cmd 6 --daemonize --log $log_file --pid $pid_file > $tempfile 2>&1");
169 PerconaTest::wait_for_files($log_file, $pid_file, $tempfile);
170-
171-$output = `ps wx | grep '$cmd 5' | grep -v grep`;
172-chomp(my $new_pid = slurp_file($pid_file));
173+my $new_pid;
174+($new_pid, $output) = PerconaTest::get_cmd_pid("$cmd 6");
175
176 like(
177 $output,
178@@ -212,12 +220,14 @@
179 'Says that old PID is not running (issue 419)'
180 );
181
182-ok(
183- $pid != $new_pid,
184+cmp_ok(
185+ $pid,
186+ '!=',
187+ $new_pid,
188 'Overwrites PID file with new PID (issue 419)'
189 );
190
191-PerconaTest::wait_until(sub { !-e $pid_file });
192+PerconaTest::wait_until(sub { !-f $pid_file });
193 ok(
194 !-f $pid_file,
195 'Re-used PID file still removed (issue 419)'
196@@ -229,21 +239,17 @@
197 # Check that it actually checks the running process.
198 # ############################################################################
199 rm_tmp_files();
200-system("$cmd 20 --daemonize --log $log_file --pid $pid_file");
201+system("$cmd 10 --daemonize --log $log_file --pid $pid_file");
202 PerconaTest::wait_for_files($pid_file, $log_file);
203 chomp($pid = slurp_file($pid_file));
204-$output = `$cmd 0 --daemonize --pid $pid_file 2>&1`;
205+$output = `$cmd 1 --daemonize --pid $pid_file 2>&1`;
206 like(
207 $output,
208 qr/PID file $pid_file exists and PID $pid is running/,
209 'Says that PID is running (issue 419)'
210 );
211
212-if ( $pid ) {
213- kill 9, $pid;
214-}
215-
216-sleep 0.25;
217+PerconaTest::kill_program(pid => $pid);
218 rm_tmp_files();
219
220 # #############################################################################
221
222=== modified file 't/pt-stalk/pt-stalk.t'
223--- t/pt-stalk/pt-stalk.t 2013-04-08 13:13:56 +0000
224+++ t/pt-stalk/pt-stalk.t 2013-08-11 02:43:48 +0000
225@@ -79,9 +79,9 @@
226 # As of v2.1.9 when --verbose was added, non-matching checks are not
227 # printed by default. So we use the --plugin to tell us when the tool
228 # has completed a cycle.
229-
230-$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");
231-
232+warn "1 before cmd";
233+$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");
234+warn "2 after cmd";
235 is(
236 $retval >> 8,
237 0,
238@@ -143,6 +143,8 @@
239 # #############################################################################
240
241 cleanup();
242+done_testing;
243+exit;
244
245 $retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --variable Threads_running --dest $dest --verbose 3 -- --defaults-file=$cnf");
246

Subscribers

People subscribed via source and target branches

to all changes: