Merge lp:~percona-toolkit-dev/percona-toolkit/fix-daemon-tests into lp:~percona-toolkit-dev/percona-toolkit/fix-pt-archiver-dry-run-bug-1199589
- fix-daemon-tests
- Merge into fix-pt-archiver-dry-run-bu...
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Nichter | Approve | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
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 | 819 | return [ sort keys %tables ]; | 819 | return [ sort keys %tables ]; |
6 | 820 | } | 820 | } |
7 | 821 | 821 | ||
8 | 822 | sub get_cmd_pid { | ||
9 | 823 | my $cmd = shift; | ||
10 | 824 | $cmd =~ s/\./\\./g; | ||
11 | 825 | $cmd =~ s/-/\\-/g; | ||
12 | 826 | my $output = `ps xww | grep -v grep | grep '$cmd'`; | ||
13 | 827 | my @cmds = $output =~ m/\n/g; | ||
14 | 828 | if ( @cmds > 1 ) { | ||
15 | 829 | die "Found " . scalar @cmds . " commands matching '$cmd': @cmds"; | ||
16 | 830 | } | ||
17 | 831 | my ($pid) = $output =~ m/^\s*(\d+)/; | ||
18 | 832 | return wantarray ? ($pid, $output) : $pid; | ||
19 | 833 | } | ||
20 | 834 | |||
21 | 835 | |||
22 | 822 | sub can_load_data { | 836 | sub can_load_data { |
23 | 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`; |
24 | 824 | return ($output || '') =~ /1/; | 838 | return ($output || '') =~ /1/; |
25 | 825 | 839 | ||
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 | 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. |
31 | 32 | # ############################################################################ | 32 | # ############################################################################ |
32 | 33 | 33 | ||
34 | 34 | 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 | 35 | die 'Cannot test Daemon.pm because t/daemonizes.pl is not working' | 35 | die 'Cannot test Daemon.pm because t/daemonizes.pl is not working' |
36 | 36 | unless $ret_val == 0; | 36 | unless $ret_val == 0; |
37 | 37 | 37 | ||
39 | 38 | PerconaTest::wait_for_files($pid_file); | 38 | PerconaTest::wait_for_files($pid_file, $log_file) |
40 | 39 | or die "$cmd did not create $pid_file and $log_file"; | ||
41 | 39 | 40 | ||
43 | 40 | my $output = `ps wx | grep '$cmd 5' | grep -v grep`; | 41 | my ($pid, $output) = PerconaTest::get_cmd_pid("$cmd 3"); |
44 | 41 | 42 | ||
45 | 42 | like( | 43 | like( |
46 | 43 | $output, | 44 | $output, |
47 | @@ -50,7 +51,6 @@ | |||
48 | 50 | 'Creates PID file' | 51 | 'Creates PID file' |
49 | 51 | ); | 52 | ); |
50 | 52 | 53 | ||
51 | 53 | my ($pid) = $output =~ /^\s*(\d+)\s+/; | ||
52 | 54 | $output = slurp_file($pid_file); | 54 | $output = slurp_file($pid_file); |
53 | 55 | chomp($output) if $output; | 55 | chomp($output) if $output; |
54 | 56 | 56 | ||
55 | @@ -60,12 +60,16 @@ | |||
56 | 60 | 'PID file has correct PID' | 60 | 'PID file has correct PID' |
57 | 61 | ); | 61 | ); |
58 | 62 | 62 | ||
65 | 63 | # Wait until the process goes away | 63 | SKIP: { |
66 | 64 | PerconaTest::wait_until(sub { !kill(0, $pid) }); | 64 | skip "Previous tests failed", 1 unless $pid; |
67 | 65 | ok( | 65 | |
68 | 66 | ! -f $pid_file, | 66 | # Wait until the process goes away |
69 | 67 | 'Removes PID file upon exit' | 67 | PerconaTest::wait_until(sub { !kill(0, $pid) }); |
70 | 68 | ); | 68 | ok( |
71 | 69 | ! -f $pid_file, | ||
72 | 70 | 'Removes PID file upon exit' | ||
73 | 71 | ); | ||
74 | 72 | } | ||
75 | 69 | 73 | ||
76 | 70 | # ############################################################################ | 74 | # ############################################################################ |
77 | 71 | # Check that STDOUT can be redirected | 75 | # Check that STDOUT can be redirected |
78 | @@ -132,12 +136,14 @@ | |||
79 | 132 | # ########################################################################## | 136 | # ########################################################################## |
80 | 133 | rm_tmp_files(); | 137 | rm_tmp_files(); |
81 | 134 | SKIP: { | 138 | SKIP: { |
84 | 135 | skip 'No /proc', 2 unless -d '/proc'; | 139 | skip 'No /proc', 1 unless -d '/proc'; |
85 | 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"; |
86 | 137 | 141 | ||
90 | 138 | system("$cmd 5 --daemonize --pid $pid_file --log $log_file"); | 142 | system("$cmd 15 --daemonize --pid $pid_file --log $log_file"); |
91 | 139 | PerconaTest::wait_for_files($pid_file); | 143 | PerconaTest::wait_for_files($pid_file, $log_file) |
92 | 140 | chomp($pid = slurp_file($pid_file)); | 144 | or die "$cmd did not create $pid_file and $log_file"; |
93 | 145 | my $pid = PerconaTest::get_cmd_pid("$cmd 15") | ||
94 | 146 | or die "Cannot get PID of $cmd 15\n" . `ps xww`; | ||
95 | 141 | my $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0" | 147 | my $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0" |
96 | 142 | : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" | 148 | : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" |
97 | 143 | : die "Cannot find fd 0 symlink in /proc/$pid"; | 149 | : die "Cannot find fd 0 symlink in /proc/$pid"; |
98 | @@ -150,38 +156,41 @@ | |||
99 | 150 | 'Reopens STDIN to /dev/null' | 156 | 'Reopens STDIN to /dev/null' |
100 | 151 | ); | 157 | ); |
101 | 152 | 158 | ||
122 | 153 | SKIP: { | 159 | PerconaTest::kill_program(pid => $pid); |
123 | 154 | skip "-t is not reliable", 1; | 160 | |
124 | 155 | rm_tmp_files(); | 161 | # SKIP: { |
125 | 156 | system("echo foo | $cmd 5 --daemonize --pid $pid_file --log $log_file"); | 162 | # skip "-t is not reliable", 1; |
126 | 157 | PerconaTest::wait_for_files($pid_file, $log_file); | 163 | # rm_tmp_files(); |
127 | 158 | chomp($pid = slurp_file($pid_file)); | 164 | # system("echo foo | $cmd 5 --daemonize --pid $pid_file --log $log_file"); |
128 | 159 | $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0" | 165 | # PerconaTest::wait_for_files($pid_file, $log_file); |
129 | 160 | : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" | 166 | # chomp($pid = slurp_file($pid_file)); |
130 | 161 | : die "Cannot find fd 0 symlink in /proc/$pid"; | 167 | # $proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0" |
131 | 162 | PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file, | 168 | # : -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0" |
132 | 163 | 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`); | 169 | # : die "Cannot find fd 0 symlink in /proc/$pid"; |
133 | 164 | $stdin = readlink $proc_fd_0; | 170 | # PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file, |
134 | 165 | like( | 171 | # 'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`); |
135 | 166 | $stdin, | 172 | # $stdin = readlink $proc_fd_0; |
136 | 167 | qr/pipe/, | 173 | # like( |
137 | 168 | 'Does not reopen STDIN to /dev/null when piped', | 174 | # $stdin, |
138 | 169 | ); | 175 | # qr/pipe/, |
139 | 170 | rm_tmp_files(); | 176 | # 'Does not reopen STDIN to /dev/null when piped', |
140 | 171 | } | 177 | # ); |
141 | 172 | }; | 178 | # rm_tmp_files(); |
142 | 179 | # } | ||
143 | 180 | } | ||
144 | 173 | 181 | ||
145 | 174 | # ########################################################################## | 182 | # ########################################################################## |
146 | 175 | # Issue 419: Daemon should check wether process with pid obtained from | 183 | # Issue 419: Daemon should check wether process with pid obtained from |
147 | 176 | # pid-file is still running | 184 | # pid-file is still running |
148 | 177 | # ########################################################################## | 185 | # ########################################################################## |
149 | 178 | rm_tmp_files(); | 186 | rm_tmp_files(); |
151 | 179 | system("$cmd 5 --daemonize --pid $pid_file >/dev/null 2>&1"); | 187 | system("$cmd 7 --daemonize --pid $pid_file >/dev/null 2>&1"); |
152 | 180 | PerconaTest::wait_for_files($pid_file); | 188 | PerconaTest::wait_for_files($pid_file); |
154 | 181 | chomp($pid = slurp_file($pid_file)); | 189 | $pid = PerconaTest::get_cmd_pid("$cmd 7") |
155 | 190 | or die "Cannot get PID of $cmd 7"; | ||
156 | 182 | kill 9, $pid; | 191 | kill 9, $pid; |
157 | 183 | sleep 0.25; | 192 | sleep 0.25; |
159 | 184 | $output = `ps wx | grep '^[ ]*$pid' | grep -v grep`; | 193 | (undef, $output) = PerconaTest::get_cmd_pid("$cmd 7"); |
160 | 185 | unlike( | 194 | unlike( |
161 | 186 | $output, | 195 | $output, |
162 | 187 | qr/daemonize/, | 196 | qr/daemonize/, |
163 | @@ -194,11 +203,10 @@ | |||
164 | 194 | 203 | ||
165 | 195 | my (undef, $tempfile) = tempfile(); | 204 | my (undef, $tempfile) = tempfile(); |
166 | 196 | 205 | ||
168 | 197 | system("$cmd 5 --daemonize --log $log_file --pid $pid_file > $tempfile 2>&1"); | 206 | system("$cmd 6 --daemonize --log $log_file --pid $pid_file > $tempfile 2>&1"); |
169 | 198 | PerconaTest::wait_for_files($log_file, $pid_file, $tempfile); | 207 | PerconaTest::wait_for_files($log_file, $pid_file, $tempfile); |
173 | 199 | 208 | my $new_pid; | |
174 | 200 | $output = `ps wx | grep '$cmd 5' | grep -v grep`; | 209 | ($new_pid, $output) = PerconaTest::get_cmd_pid("$cmd 6"); |
172 | 201 | chomp(my $new_pid = slurp_file($pid_file)); | ||
175 | 202 | 210 | ||
176 | 203 | like( | 211 | like( |
177 | 204 | $output, | 212 | $output, |
178 | @@ -212,12 +220,14 @@ | |||
179 | 212 | 'Says that old PID is not running (issue 419)' | 220 | 'Says that old PID is not running (issue 419)' |
180 | 213 | ); | 221 | ); |
181 | 214 | 222 | ||
184 | 215 | ok( | 223 | cmp_ok( |
185 | 216 | $pid != $new_pid, | 224 | $pid, |
186 | 225 | '!=', | ||
187 | 226 | $new_pid, | ||
188 | 217 | 'Overwrites PID file with new PID (issue 419)' | 227 | 'Overwrites PID file with new PID (issue 419)' |
189 | 218 | ); | 228 | ); |
190 | 219 | 229 | ||
192 | 220 | PerconaTest::wait_until(sub { !-e $pid_file }); | 230 | PerconaTest::wait_until(sub { !-f $pid_file }); |
193 | 221 | ok( | 231 | ok( |
194 | 222 | !-f $pid_file, | 232 | !-f $pid_file, |
195 | 223 | 'Re-used PID file still removed (issue 419)' | 233 | 'Re-used PID file still removed (issue 419)' |
196 | @@ -229,21 +239,17 @@ | |||
197 | 229 | # Check that it actually checks the running process. | 239 | # Check that it actually checks the running process. |
198 | 230 | # ############################################################################ | 240 | # ############################################################################ |
199 | 231 | rm_tmp_files(); | 241 | rm_tmp_files(); |
201 | 232 | system("$cmd 20 --daemonize --log $log_file --pid $pid_file"); | 242 | system("$cmd 10 --daemonize --log $log_file --pid $pid_file"); |
202 | 233 | PerconaTest::wait_for_files($pid_file, $log_file); | 243 | PerconaTest::wait_for_files($pid_file, $log_file); |
203 | 234 | chomp($pid = slurp_file($pid_file)); | 244 | chomp($pid = slurp_file($pid_file)); |
205 | 235 | $output = `$cmd 0 --daemonize --pid $pid_file 2>&1`; | 245 | $output = `$cmd 1 --daemonize --pid $pid_file 2>&1`; |
206 | 236 | like( | 246 | like( |
207 | 237 | $output, | 247 | $output, |
208 | 238 | qr/PID file $pid_file exists and PID $pid is running/, | 248 | qr/PID file $pid_file exists and PID $pid is running/, |
209 | 239 | 'Says that PID is running (issue 419)' | 249 | 'Says that PID is running (issue 419)' |
210 | 240 | ); | 250 | ); |
211 | 241 | 251 | ||
217 | 242 | if ( $pid ) { | 252 | PerconaTest::kill_program(pid => $pid); |
213 | 243 | kill 9, $pid; | ||
214 | 244 | } | ||
215 | 245 | |||
216 | 246 | sleep 0.25; | ||
218 | 247 | rm_tmp_files(); | 253 | rm_tmp_files(); |
219 | 248 | 254 | ||
220 | 249 | # ############################################################################# | 255 | # ############################################################################# |
221 | 250 | 256 | ||
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 | 79 | # As of v2.1.9 when --verbose was added, non-matching checks are not | 79 | # As of v2.1.9 when --verbose was added, non-matching checks are not |
227 | 80 | # printed by default. So we use the --plugin to tell us when the tool | 80 | # printed by default. So we use the --plugin to tell us when the tool |
228 | 81 | # has completed a cycle. | 81 | # has completed a cycle. |
232 | 82 | 82 | warn "1 before cmd"; | |
233 | 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"); |
234 | 84 | 84 | warn "2 after cmd"; | |
235 | 85 | is( | 85 | is( |
236 | 86 | $retval >> 8, | 86 | $retval >> 8, |
237 | 87 | 0, | 87 | 0, |
238 | @@ -143,6 +143,8 @@ | |||
239 | 143 | # ############################################################################# | 143 | # ############################################################################# |
240 | 144 | 144 | ||
241 | 145 | cleanup(); | 145 | cleanup(); |
242 | 146 | done_testing; | ||
243 | 147 | exit; | ||
244 | 146 | 148 | ||
245 | 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"); |
246 | 148 | 150 |