mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-12 06:00:14 +00:00
Test --plugin.
This commit is contained in:
@@ -1680,11 +1680,13 @@ process as a backgrounded subshell.
|
|||||||
=item after_collect_hook
|
=item after_collect_hook
|
||||||
|
|
||||||
Called after running a collector process. The PID of the collector process
|
Called after running a collector process. The PID of the collector process
|
||||||
is passed as the first argument.
|
is passed as the first argument. This hook is called before
|
||||||
|
C<after_collect_sleep_hook>.
|
||||||
|
|
||||||
=item after_collect_sleep_hook
|
=item after_collect_sleep_hook
|
||||||
|
|
||||||
Called after sleeping L<"--sleep"> seconds for the collector process to finish.
|
Called after sleeping L<"--sleep"> seconds for the collector process to finish.
|
||||||
|
This hook is called after C<after_collect_hook>.
|
||||||
|
|
||||||
=item after_stalk_hook
|
=item after_stalk_hook
|
||||||
|
|
||||||
|
74
t/pt-stalk/plugin.t
Normal file
74
t/pt-stalk/plugin.t
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||||
|
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||||
|
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||||
|
};
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings FATAL => 'all';
|
||||||
|
use English qw(-no_match_vars);
|
||||||
|
use Test::More;
|
||||||
|
use Time::HiRes qw(sleep);
|
||||||
|
|
||||||
|
use PerconaTest;
|
||||||
|
use DSNParser;
|
||||||
|
use Sandbox;
|
||||||
|
|
||||||
|
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||||
|
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||||
|
my $dbh = $sb->get_dbh_for('master');
|
||||||
|
|
||||||
|
if ( !$dbh ) {
|
||||||
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
|
}
|
||||||
|
|
||||||
|
my $cnf = "/tmp/12345/my.sandbox.cnf";
|
||||||
|
my $pid_file = "/tmp/pt-stalk.pid.$PID";
|
||||||
|
my $log_file = "/tmp/pt-stalk.log.$PID";
|
||||||
|
my $dest = "/tmp/pt-stalk.collect.$PID";
|
||||||
|
my $output;
|
||||||
|
my $retval;
|
||||||
|
my $pid;
|
||||||
|
|
||||||
|
diag(`rm $pid_file 2>/dev/null`);
|
||||||
|
diag(`rm $log_file 2>/dev/null`);
|
||||||
|
diag(`mkdir $dest`);
|
||||||
|
|
||||||
|
# We'll have to watch Uptime since it's the only status var that's going
|
||||||
|
# to be predictable.
|
||||||
|
my (undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
|
||||||
|
my $threshold = $uptime + 2;
|
||||||
|
|
||||||
|
$retval = system("$trunk/bin/pt-stalk --iterations 1 --dest $dest --variable Uptime --threshold $threshold --cycles 1 --run-time 2 --pid $pid_file --plugin $trunk/t/pt-stalk/samples/plugin001.sh -- --defaults-file=$cnf >$log_file 2>&1");
|
||||||
|
|
||||||
|
PerconaTest::wait_until(sub { !-f $pid_file });
|
||||||
|
|
||||||
|
is(
|
||||||
|
$retval >> 8,
|
||||||
|
0,
|
||||||
|
"Exit 0"
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach my $hook (qw(
|
||||||
|
before_stalk_hook
|
||||||
|
before_collect_hook
|
||||||
|
after_collect_hook
|
||||||
|
after_collect_sleep_hook
|
||||||
|
after_stalk_hook
|
||||||
|
)) {
|
||||||
|
ok(
|
||||||
|
-f "$dest/$hook",
|
||||||
|
"$hook called"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
# #############################################################################
|
||||||
|
# Done.
|
||||||
|
# #############################################################################
|
||||||
|
diag(`rm $pid_file 2>/dev/null`);
|
||||||
|
diag(`rm $log_file 2>/dev/null`);
|
||||||
|
diag(`rm -rf $dest 2>/dev/null`);
|
||||||
|
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||||
|
done_testing;
|
21
t/pt-stalk/samples/plugin001.sh
Normal file
21
t/pt-stalk/samples/plugin001.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
before_stalk_hook() {
|
||||||
|
date >> "$OPT_DEST/before_stalk_hook"
|
||||||
|
}
|
||||||
|
|
||||||
|
before_collect_hook() {
|
||||||
|
date >> "$OPT_DEST/before_collect_hook"
|
||||||
|
}
|
||||||
|
|
||||||
|
after_collect_hook() {
|
||||||
|
date >> "$OPT_DEST/after_collect_hook"
|
||||||
|
}
|
||||||
|
|
||||||
|
after_collect_sleep_hook() {
|
||||||
|
date >> "$OPT_DEST/after_collect_sleep_hook"
|
||||||
|
}
|
||||||
|
|
||||||
|
after_stalk_hook() {
|
||||||
|
date >> "$OPT_DEST/after_stalk_hook"
|
||||||
|
}
|
Reference in New Issue
Block a user