~percona-toolkit-dev/percona-toolkit/release-2.2.2

58 by Daniel
Tweak, fix, and add tests so every tool passes.
1
#!/usr/bin/env perl
2
3
BEGIN {
4
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
7
};
8
9
use strict;
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
12
use Test::More;
109.3.51 by Daniel Nichter
Add and test --config to pt-stalk.
13
use Time::HiRes qw(sleep);
58 by Daniel
Tweak, fix, and add tests so every tool passes.
14
15
use PerconaTest;
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
16
use DSNParser;
17
use Sandbox;
18
19
my $dp = new DSNParser(opts=>$dsn_opts);
20
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
21
my $dbh = $sb->get_dbh_for('master');
22
23
if ( !$dbh ) {
24
   plan skip_all => 'Cannot connect to sandbox master';
25
}
26
27
my $cnf      = "/tmp/12345/my.sandbox.cnf";
28
my $pid_file = "/tmp/pt-stalk.pid.$PID";
29
my $log_file = "/tmp/pt-stalk.log.$PID";
30
my $dest     = "/tmp/pt-stalk.collect.$PID";
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
31
my $int_file = "/tmp/pt-stalk-after-interval-sleep";
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
32
my $pid;
33
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
34
sub cleanup {
35
   diag(`rm $pid_file $log_file $int_file 2>/dev/null`);
36
   diag(`rm -rf $dest 2>/dev/null`);
37
}
38
39
sub wait_n_cycles {
40
   my ($n) = @_;
41
   PerconaTest::wait_until(
42
      sub {
43
         return 0 unless -f "$dest/after_interval_sleep";
44
         my $n_cycles = `wc -l "$dest/after_interval_sleep"  | awk '{print \$1}'`;
45
         $n_cycles ||= '';
46
         chomp($n_cycles);
47
         return ($n_cycles || 0) >= $n; 
48
      },
49
      1.5,
50
      15
51
   );
52
}
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
53
54
# ###########################################################################
55
# Test that it won't run if can't connect to MySQL.
56
# ###########################################################################
57
94.2.96 by Baron Schwartz
update pt-stalk test so it works more reliably when passwordless login is set up, and so the cycle-count test is OK with nondeterminism of +/- 1 second
58
my $retval = system("$trunk/bin/pt-stalk -- --no-defaults --protocol socket --socket /dev/null  >$log_file 2>&1");
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
59
my $output = `cat $log_file`;
60
61
like(
62
   $output,
63
   qr/Cannot connect to MySQL/,
64
   "Cannot connect to MySQL"
65
);
66
67
is(
68
   $retval >> 8,
69
   1,
70
   "Exit 1"
71
);
72
73
# ###########################################################################
74
# Test that it runs and dies normally.
75
# ###########################################################################
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
76
77
cleanup();
78
79
# 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 tool
81
# has completed a cycle.
82
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");
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
84
85
is(
86
   $retval >> 8,
87
   0,
88
   "Parent exit 0"
89
);
90
91
PerconaTest::wait_for_files($pid_file, $log_file);
92
ok(
93
   -f $pid_file,
94
   "Creates PID file"
95
);
96
97
ok(
98
   -f $log_file,
99
   "Creates log file"
100
);
101
102
sleep 1;
103
104
ok(
105
   -d $dest,
106
   "Creates --dest (collect) dir"
107
);
108
427.1.3 by Daniel Nichter
Really wait for expected data in files.
109
chomp($pid = `cat $pid_file 2>/dev/null`);
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
110
$retval = system("kill -0 $pid");
111
is(
112
   $retval >> 0,
113
   0,
427.1.3 by Daniel Nichter
Really wait for expected data in files.
114
   "pt-stalk is running"
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
115
);
116
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
117
wait_n_cycles(2);
118
PerconaTest::kill_program(pid_file => $pid_file);
119
427.1.3 by Daniel Nichter
Really wait for expected data in files.
120
$output = `cat $log_file 2>/dev/null`;
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
121
unlike(
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
122
   $output,
571.7.1 by Brian Fraser
Fix for 1156867: pt-stalk doesn't print the function name being used
123
   qr/Check results: status\(Threads_running\)=\d+, matched=no, cycles_true=0/,
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
124
   "Non-matching results not logged because --verbose=2"
427.1.5 by Daniel Nichter
Include collector output in diag.
125
) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
126
427.1.3 by Daniel Nichter
Really wait for expected data in files.
127
PerconaTest::wait_until(sub { !-f $pid_file });
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
128
129
ok(
130
   ! -f $pid_file,
131
   "Removes PID file"
132
);
133
427.1.3 by Daniel Nichter
Really wait for expected data in files.
134
$output = `cat $log_file 2>/dev/null`;
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
135
like(
136
   $output,
137
   qr/Caught signal, exiting/,
138
   "Caught signal logged"
427.1.5 by Daniel Nichter
Include collector output in diag.
139
) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
140
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
141
# #############################################################################
142
# --verbose 3 (non-matching results)
143
# #############################################################################
144
145
cleanup();
146
519.1.4 by Brian Fraser
update-samples on pt-ms
147
$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --variable Threads_running --dest $dest --verbose 3 -- --defaults-file=$cnf");
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
148
149
PerconaTest::wait_for_files($pid_file, $log_file);
150
PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null");
151
PerconaTest::kill_program(pid_file => $pid_file);
152
153
$output = `cat $log_file 2>/dev/null`;
154
like(
155
   $output,
571.7.1 by Brian Fraser
Fix for 1156867: pt-stalk doesn't print the function name being used
156
   qr/Check results: status\(Threads_running\)=\d+, matched=no, cycles_true=0/,
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
157
   "Matching results logged with --verbose 3"
519.1.4 by Brian Fraser
update-samples on pt-ms
158
) or diag(`cat $dest/*-output 2>/dev/null`);
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
159
160
# #############################################################################
161
# --verbose 1 (just errors and warnings)
162
# #############################################################################
163
164
cleanup();
165
166
$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 1 --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf");
167
168
PerconaTest::wait_for_files($pid_file, $log_file);
169
wait_n_cycles(2);
170
PerconaTest::kill_program(pid_file => $pid_file);
171
172
$output = `cat $log_file 2>/dev/null`;
173
174
like(
175
   $output,
176
   qr/Caught signal, exiting/,
177
   "Warning logged (--verbose 1)"
178
);
179
180
unlike(
181
   $output,
182
   qr/Start|Collect|Check/i,
183
   "No run info log (--verbose 1)"
184
);
185
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
186
# ###########################################################################
187
# Test collect.
188
# ###########################################################################
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
189
190
cleanup();
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
191
192
# We'll have to watch Uptime since it's the only status var that's going
193
# to be predictable.
194
my (undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
195
my $threshold = $uptime + 2;
196
427.1.1 by Daniel Nichter
Wait for collectors before exiting. Use wait_until instead of sleep in pt-stalk.t, and add lots of diag info when tests fail.
197
$retval = system("$trunk/bin/pt-stalk --iterations 1 --dest $dest --variable Uptime --threshold $threshold --cycles 2 --run-time 2 --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");
198
199
PerconaTest::wait_until(sub { !-f $pid_file });
200
201
$output = `cat $dest/*-trigger 2>/dev/null`;
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
202
like(
203
   $output,
571.7.1 by Brian Fraser
Fix for 1156867: pt-stalk doesn't print the function name being used
204
   qr/Check results: status\(Uptime\)=\d+, matched=yes, cycles_true=2/,
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
205
   "Collect triggered"
427.1.1 by Daniel Nichter
Wait for collectors before exiting. Use wait_until instead of sleep in pt-stalk.t, and add lots of diag info when tests fail.
206
)
207
or diag(
427.1.5 by Daniel Nichter
Include collector output in diag.
208
   'output',    $output,
209
   'log file',  `cat $log_file 2>/dev/null`,
210
   'collector', `cat $dest/*-output 2>/dev/null`,
211
   'dest',      `ls -l $dest/ 2>/dev/null`,
212
   'df',        `cat $dest/*-df 2>/dev/null`,
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
213
);
214
94.2.96 by Baron Schwartz
update pt-stalk test so it works more reliably when passwordless login is set up, and so the cycle-count test is OK with nondeterminism of +/- 1 second
215
# There is some nondeterminism here. Sometimes it'll run for 2 samples because
216
# the samples may not be precisely 1 second apart.
427.1.1 by Daniel Nichter
Wait for collectors before exiting. Use wait_until instead of sleep in pt-stalk.t, and add lots of diag info when tests fail.
217
chomp($output = `cat $dest/*-df 2>/dev/null | grep -c '^TS'`);
94.2.96 by Baron Schwartz
update pt-stalk test so it works more reliably when passwordless login is set up, and so the cycle-count test is OK with nondeterminism of +/- 1 second
218
ok(
401.2.2 by Daniel Nichter
Remove pt conf files before running Jenkins test else they can cause weird results. Make pt-stalk --collect run-time test more liberal.
219
   $output >= 1 && $output <= 3,
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
220
   "Collect ran for --run-time"
427.1.1 by Daniel Nichter
Wait for collectors before exiting. Use wait_until instead of sleep in pt-stalk.t, and add lots of diag info when tests fail.
221
)
222
or diag(
427.1.5 by Daniel Nichter
Include collector output in diag.
223
   'output',    $output,
224
   'log file',  `cat $log_file 2>/dev/null`,
225
   'collector', `cat $dest/*-output 2>/dev/null`,
226
   'dest',      `ls -l $dest/ 2>/dev/null`,
227
   'df',        `cat $dest/*-df 2>/dev/null`,
427.1.1 by Daniel Nichter
Wait for collectors before exiting. Use wait_until instead of sleep in pt-stalk.t, and add lots of diag info when tests fail.
228
);
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
229
94.2.58 by Daniel Nichter
Make pt-stalk/pt-stalk.t stable. Add PerconaTest::not_running().
230
ok(
231
   PerconaTest::not_running("pt-stalk --iterations 1"),
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
232
   "pt-stalk is not running"
233
);
58 by Daniel
Tweak, fix, and add tests so every tool passes.
234
427.1.1 by Daniel Nichter
Wait for collectors before exiting. Use wait_until instead of sleep in pt-stalk.t, and add lots of diag info when tests fail.
235
$output = `cat $dest/*-trigger 2>/dev/null`;
109.3.43 by Daniel Nichter
Log how pt-stalk was ran. Update modules in tool. Tweak 'Starting' and 'Exiting' log lines.
236
like(
237
   $output,
238
   qr/pt-stalk ran with --function=status --variable=Uptime --threshold=$threshold/,
239
   "Trigger file logs how pt-stalk was ran"
240
);
241
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
242
chomp($output = `cat $log_file 2>/dev/null | grep 'Collect [0-9] PID'`);
109.3.69 by Daniel Nichter
Log collector PID.
243
like(
244
   $output,
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
245
   qr/Collect 1 PID \d+/,
109.3.69 by Daniel Nichter
Log collector PID.
246
   "Collector PID logged"
427.1.5 by Daniel Nichter
Include collector output in diag.
247
)
248
or diag(
249
   'output',    $output,
250
   'log file',  `cat $log_file 2>/dev/null`,
251
   'collector', `cat $dest/*-output 2>/dev/null`,
252
);
109.3.69 by Daniel Nichter
Log collector PID.
253
109.3.57 by Daniel Nichter
Implement --[no]collect.
254
# ###########################################################################
255
# Triggered but --no-collect.
256
# ###########################################################################
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
257
258
cleanup();
109.3.57 by Daniel Nichter
Implement --[no]collect.
259
260
(undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
261
$threshold = $uptime + 2;
262
263
$retval = system("$trunk/bin/pt-stalk --no-collect --iterations 1 --dest $dest  --variable Uptime --threshold $threshold --cycles 1 --run-time 1 --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");
264
427.1.1 by Daniel Nichter
Wait for collectors before exiting. Use wait_until instead of sleep in pt-stalk.t, and add lots of diag info when tests fail.
265
PerconaTest::wait_until(sub { !-f $pid_file });
109.3.57 by Daniel Nichter
Implement --[no]collect.
266
427.1.2 by Daniel Nichter
Make "not stalking" tests more reliable.
267
$output = `cat $log_file 2>/dev/null`;
109.3.57 by Daniel Nichter
Implement --[no]collect.
268
like(
269
   $output,
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
270
   qr/Collect 1 triggered/,
109.3.57 by Daniel Nichter
Implement --[no]collect.
271
   "Collect triggered"
272
);
273
274
ok(
275
   ! -f "$dest/*",
276
   "No files collected"
427.1.5 by Daniel Nichter
Include collector output in diag.
277
) or diag(`ls -l $dest/ 2>/dev/null`);
109.3.57 by Daniel Nichter
Implement --[no]collect.
278
94.2.58 by Daniel Nichter
Make pt-stalk/pt-stalk.t stable. Add PerconaTest::not_running().
279
ok(
280
   PerconaTest::not_running("pt-stalk --no-collect"),
109.3.57 by Daniel Nichter
Implement --[no]collect.
281
   "pt-stalk is not running"
282
);
109.3.51 by Daniel Nichter
Add and test --config to pt-stalk.
283
284
# #############################################################################
285
# --config
286
# #############################################################################
287
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
288
cleanup();
289
109.3.51 by Daniel Nichter
Add and test --config to pt-stalk.
290
diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`);
291
diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`);
292
293
system "$trunk/bin/pt-stalk --dest $dest --pid $pid_file >$log_file 2>&1 &";
109.3.52 by Daniel Nichter
Merge lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-2.0-docs r155.
294
PerconaTest::wait_for_files($pid_file);
109.3.51 by Daniel Nichter
Add and test --config to pt-stalk.
295
sleep 1;
296
chomp($pid = `cat $pid_file`);
297
$retval = system("kill $pid 2>/dev/null");
298
is(
299
   $retval >> 0,
300
   0,
301
   "Killed pt-stalk"
302
);
303
427.1.5 by Daniel Nichter
Include collector output in diag.
304
$output = `cat $log_file 2>/dev/null`;
109.3.51 by Daniel Nichter
Add and test --config to pt-stalk.
305
like(
306
   $output,
571.7.1 by Brian Fraser
Fix for 1156867: pt-stalk doesn't print the function name being used
307
   qr/Check results: status\(Aborted_connects\)=|variable=Aborted_connects/,
109.3.51 by Daniel Nichter
Add and test --config to pt-stalk.
308
   "Read default config file"
309
);
310
311
diag(`rm $ENV{HOME}/.pt-stalk.conf`);
312
diag(`cp $ENV{HOME}/.pt-stalk.conf.original $ENV{HOME}/.pt-stalk.conf 2>/dev/null`);
313
58 by Daniel
Tweak, fix, and add tests so every tool passes.
314
# #############################################################################
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
315
# Don't stalk, just collect.
316
# #############################################################################
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
317
318
cleanup();
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
319
545.1.1 by Daniel Nichter
Make --no-stalk _not_ force --iterations and other options. Extensively update the tool's docs.
320
# As of 2.2, --no-stalk means just that: don't stalk, just collect, so
321
# we have to specify --iterations=1 else the tool will continue to run,
322
# whereas in 2.1 --no-stalk implied/forced "collect once and exit".
323
324
$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk --pid $pid_file --iterations 1 -- --defaults-file=$cnf >$log_file 2>&1");
427.1.2 by Daniel Nichter
Make "not stalking" tests more reliable.
325
326
PerconaTest::wait_until(sub { !-f $pid_file });
327
328
$output = `cat $dest/nostalk-trigger 2>/dev/null`;
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
329
like(
330
   $output,
331
   qr/Not stalking/,
332
   "Not stalking, collect triggered"
427.1.5 by Daniel Nichter
Include collector output in diag.
333
)
334
or diag(
335
   'dest',      `ls -l $dest/ 2>/dev/null`,
336
   'log_file',  `cat $log_file 2>/dev/null`,
337
   'collector', `cat $dest/*-output 2>/dev/null`,
338
);
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
339
427.1.2 by Daniel Nichter
Make "not stalking" tests more reliable.
340
chomp($output = `grep -c '^TS' $dest/nostalk-df 2>/dev/null`);
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
341
is(
342
   $output,
343
   2,
344
   "Not stalking, collect ran for --run-time"
427.1.5 by Daniel Nichter
Include collector output in diag.
345
)
346
or diag(
347
   'dest',      `ls -l $dest/ 2>/dev/null`,
348
   'log_file',  `cat $log_file 2>/dev/null`,
349
   'collector', `cat $dest/*-output 2>/dev/null`,
350
);
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
351
221.2.2 by Daniel Nichter
Test that vmstatu runs for --run-time with --no-stalk.
352
my $vmstat = `which vmstat 2>/dev/null`;
353
SKIP: {
354
   skip "vmstat is not installed", 1 unless $vmstat;
355
   chomp(my $n=`awk '/[ ]*[0-9]/ { n += 1 } END { print n }' "$dest/nostalk-vmstat"`);
356
   is(
357
      $n,
358
      "2",
359
      "vmstat ran for --run-time seconds (bug 955860)"
360
   );
361
};
362
183.2.2 by Daniel Nichter
Add another test to verify collect.
363
is(
427.1.2 by Daniel Nichter
Make "not stalking" tests more reliable.
364
   `cat $dest/nostalk-hostname 2>/dev/null`,
183.2.2 by Daniel Nichter
Add another test to verify collect.
365
   `hostname`,
366
   "Not stalking, collect gathered data"
427.1.5 by Daniel Nichter
Include collector output in diag.
367
)
368
or diag(
369
   'dest',      `ls -l $dest/ 2>/dev/null`,
370
   'log_file',  `cat $log_file 2>/dev/null`,
371
   'collector', `cat $dest/*-output 2>/dev/null`,
372
);
183.2.2 by Daniel Nichter
Add another test to verify collect.
373
94.2.58 by Daniel Nichter
Make pt-stalk/pt-stalk.t stable. Add PerconaTest::not_running().
374
ok(
375
   PerconaTest::not_running("pt-stalk --no-stalk"),
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
376
   "Not stalking, pt-stalk is not running"
427.1.5 by Daniel Nichter
Include collector output in diag.
377
)
378
or diag(
379
   'dest',      `ls -l $dest/ 2>/dev/null`,
380
   'log_file',  `cat $log_file 2>/dev/null`,
381
   'collector', `cat $dest/*-output 2>/dev/null`,
382
);
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
383
354.3.1 by fraserb at gmail
Bug 942114: bad "find" usage in pt-stalk
384
# ############################################################################
385
# bad "find" usage in purge_samples gives 
386
# https://bugs.launchpad.net/percona-toolkit/+bug/942114
387
# ############################################################################
388
389
use File::Temp qw( tempdir );
390
391
my $tempdir = tempdir( CLEANUP => 1 );
392
393
my $script = <<"EOT";
394
. $trunk/bin/pt-stalk
395
purge_samples $tempdir 10000 2>&1
396
EOT
397
398
$output = `$script`;
399
400
unlike(
401
   $output,
402
   qr/\Qfind: warning: you have specified the -depth option/,
403
   "Bug 942114: no bad find usage"
404
);
405
183.2.1 by Daniel Nichter
Add and test --[no]stalk to pt-stalk. Fix ps in pt-stalk tests. Add PerconaTest::wait_for_sh().
406
# #############################################################################
58 by Daniel
Tweak, fix, and add tests so every tool passes.
407
# Done.
408
# #############################################################################
503.9.3 by Daniel Nichter
Test --verbose. Remove global default OPT_VERBOSE from log_warn_die.sh so tool's option can set it.
409
cleanup();
109.3.27 by Daniel Nichter
Test pt-stalk. Fix disk space+margin check. Fix checking --iterations. Add EXIT_REASON. Fix grepping status var.
410
diag(`rm -rf $dest 2>/dev/null`);
94.2.45 by Daniel Nichter
Re-add calls to Sandbox::ok().
411
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
354.3.1 by fraserb at gmail
Bug 942114: bad "find" usage in pt-stalk
412
done_testing;