mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-29 01:02:47 +08:00
t/pt-deadlock-logger/standard_options.t: Modernize the tests to stop relying on sleep(), modify an ancient test that was looking for mt-deadlock-logger
This commit is contained in:
@@ -65,41 +65,46 @@ $dbh1->do('USE test');
|
|||||||
$dbh1->do('DROP TABLE IF EXISTS deadlocks');
|
$dbh1->do('DROP TABLE IF EXISTS deadlocks');
|
||||||
$dbh1->do("$deadlocks_tbl");
|
$dbh1->do("$deadlocks_tbl");
|
||||||
|
|
||||||
`$cmd --dest D=test,t=deadlocks --daemonize --run-time 1s --interval 1s --pid /tmp/mk-deadlock-logger.pid 1>/dev/null 2>/dev/null`;
|
my $pid_file = '/tmp/mk-deadlock-logger.pid';
|
||||||
$output = `ps -eaf | grep '$cmd \-\-dest '`;
|
unlink $pid_file
|
||||||
like($output, qr/$cmd/, 'It lives daemonized');
|
and diag("Unlinked existing $pid_file");
|
||||||
ok(-f '/tmp/mk-deadlock-logger.pid', 'PID file created');
|
|
||||||
|
|
||||||
|
`$cmd --dest D=test,t=deadlocks --daemonize --run-time 6s --interval 1s --pid $pid_file 1>/dev/null 2>/dev/null`;
|
||||||
|
$output = `ps -eaf | grep '$cmd \-\-dest '`;
|
||||||
|
like($output, qr/\Q$cmd/, 'It lives daemonized');
|
||||||
|
|
||||||
|
PerconaTest::wait_for_files($pid_file);
|
||||||
|
ok(-f $pid_file, 'PID file created');
|
||||||
my ($pid) = $output =~ /\s+(\d+)\s+/;
|
my ($pid) = $output =~ /\s+(\d+)\s+/;
|
||||||
$output = `cat /tmp/mk-deadlock-logger.pid`;
|
chomp($output = slurp_file($pid_file));
|
||||||
is($output, $pid, 'PID file has correct PID');
|
is($output, $pid, 'PID file has correct PID');
|
||||||
|
|
||||||
# Kill it
|
# Kill it
|
||||||
sleep 2;
|
PerconaTest::wait_until(sub { !kill 0, $pid });
|
||||||
ok(! -f '/tmp/mk-deadlock-logger.pid', 'PID file removed');
|
ok(! -f $pid_file, 'PID file removed');
|
||||||
|
|
||||||
# Check that it won't run if the PID file already exists (issue 383).
|
# Check that it won't run if the PID file already exists (issue 383).
|
||||||
diag(`touch /tmp/mk-deadlock-logger.pid`);
|
diag(`touch $pid_file`);
|
||||||
ok(
|
ok(
|
||||||
-f '/tmp/mk-deadlock-logger.pid',
|
-f $pid_file,
|
||||||
'PID file already exists'
|
'PID file already exists'
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = `$cmd --dest D=test,t=deadlocks --daemonize --run-time 1s --interval 1s --pid /tmp/mk-deadlock-logger.pid 2>&1`;
|
$output = `$cmd --dest D=test,t=deadlocks --daemonize --run-time 1s --interval 1s --pid $pid_file 2>&1`;
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/PID file .+ already exists/,
|
qr/PID file .+ already exists/,
|
||||||
'Does not run if PID file already exists'
|
'Does not run if PID file already exists'
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = `ps -eaf | grep 'mk-deadlock-logger \-\-dest '`;
|
$output = `ps -eaf | grep 'pt-deadlock-logger \-\-dest '`;
|
||||||
unlike(
|
unlike(
|
||||||
$output,
|
$output,
|
||||||
qr/$cmd/,
|
qr/$cmd/,
|
||||||
'It does not lived daemonized'
|
'It does not lived daemonized'
|
||||||
);
|
);
|
||||||
|
|
||||||
diag(`rm -rf /tmp/mk-deadlock-logger.pid`);
|
unlink $pid_file;
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
|
|||||||
Reference in New Issue
Block a user