Don't use literal values for t/pt-heartbeat/basics.t 'It is being updated' test. Use direct call rather than backticks.

This commit is contained in:
Daniel Nichter
2012-10-25 15:57:22 -06:00
parent 5b4b3886b2
commit 7b5e2fc7a2

View File

@@ -10,6 +10,7 @@ use strict;
use warnings FATAL => 'all'; use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Test::More; use Test::More;
use Data::Dumper;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
@@ -26,9 +27,6 @@ if ( !$master_dbh ) {
elsif ( !$slave1_dbh ) { elsif ( !$slave1_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave1'; plan skip_all => 'Cannot connect to sandbox slave1';
} }
else {
plan tests => 22;
}
$sb->create_dbs($master_dbh, ['test']); $sb->create_dbs($master_dbh, ['test']);
@@ -46,13 +44,30 @@ $master_dbh->do(q{CREATE TABLE test.heartbeat (
id int NOT NULL PRIMARY KEY, id int NOT NULL PRIMARY KEY,
ts datetime NOT NULL ts datetime NOT NULL
) ENGINE=MEMORY}); ) ENGINE=MEMORY});
$sb->wait_for_slaves;
# Issue: pt-heartbeat should check that the heartbeat table has a row # Issue: pt-heartbeat should check that the heartbeat table has a row
$output = `$cmd -D test --check --no-insert-heartbeat-row 2>&1`; $output = output(
like($output, qr/heartbeat table is empty/ms, 'Dies on empty heartbeat table with --check (issue 45)'); sub { pt_heartbeat::main('-F', $cnf,
qw(-D test --check --no-insert-heartbeat-row)) },
stderr => 1,
);
like(
$output,
qr/heartbeat table is empty/ms,
'Dies on empty heartbeat table with --check (issue 45)'
);
$output = `$cmd -D test --monitor --run-time 1s --no-insert-heartbeat-row 2>&1`; $output = output(
like($output, qr/heartbeat table is empty/ms, 'Dies on empty heartbeat table with --monitor (issue 45)'); sub { pt_heartbeat::main('-F', $cnf,
qw(-D test --monitor --run-time 1s --no-insert-heartbeat-row)) },
stderr => 1,
);
like(
$output,
qr/heartbeat table is empty/ms,
'Dies on empty heartbeat table with --monitor (issue 45)'
);
$output = output( $output = output(
sub { pt_heartbeat::main('-F', $cnf, qw(-D test --check)) }, sub { pt_heartbeat::main('-F', $cnf, qw(-D test --check)) },
@@ -65,34 +80,47 @@ is(
); );
# Run one instance with --replace to create the table. # Run one instance with --replace to create the table.
`$cmd -D test --update --replace --run-time 1s`; output(
ok($master_dbh->selectrow_array('select id from test.heartbeat'), 'Record is there'); sub { pt_heartbeat::main('-F', $cnf,
qw(-D test --update --replace --run-time 1s)) },
stderr => 1,
);
ok(
$master_dbh->selectrow_array('select id from test.heartbeat'),
'Record is there'
);
# Check the delay and ensure it is only a single line with nothing but the # Check the delay and ensure it is only a single line with nothing but the
# delay (no leading whitespace or anything). # delay (no leading whitespace or anything).
$output = `$cmd -D test --check`; output(
sub { pt_heartbeat::main('-F', $cnf, qw(-D test --check)) },
stderr => 1,
);
chomp $output; chomp $output;
like($output, qr/^\d+$/, 'Output is just a number'); like($output, qr/^\d+$/, 'Output is just a number');
# Start one daemonized instance to update it # Start one daemonized instance to update it
system("$cmd --daemonize -D test --update --run-time 3s --pid $pid_file 1>/dev/null 2>/dev/null"); system("$cmd --daemonize -D test --update --run-time 3s --pid $pid_file 1>/dev/null 2>/dev/null");
PerconaTest::wait_for_files($pid_file);
$output = `$ps_grep_cmd`; $output = `$ps_grep_cmd`;
like($output, qr/$cmd/, 'It is running'); like($output, qr/$cmd/, 'It is running');
PerconaTest::wait_for_files($pid_file);
ok(-f $pid_file, 'PID file created'); ok(-f $pid_file, 'PID file created');
my ($pid) = $output =~ /^\s*(\d+)\s+/; my ($pid) = $output =~ /^\s*(\d+)\s+/;
$output = `cat $pid_file` if -f $pid_file; $output = `cat $pid_file` if -f $pid_file;
is($output, $pid, 'PID file has correct PID'); is($output, $pid, 'PID file has correct PID');
$output = `$cmd -D test --monitor --run-time 1s`; $output = `$cmd -D test --monitor --run-time 1s`;
chomp ($output); if ( $output ) {
is ( chomp ($output);
$output =~ s/\d/0/g;
}
is(
$output, $output,
' 0s [ 0.00s, 0.00s, 0.00s ]', ' 0s [ 0.00s, 0.00s, 0.00s ]',
'It is being updated', 'It is being updated',
); );
sleep(3); PerconaTest::wait_until(sub { !-f $pid_file });
$output = `$ps_grep_cmd`; $output = `$ps_grep_cmd`;
chomp $output; chomp $output;
unlike($output, qr/$cmd/, 'It is not running anymore'); unlike($output, qr/$cmd/, 'It is not running anymore');
@@ -120,20 +148,32 @@ $master_dbh->do('drop table if exists test.heartbeat'); # This will kill it
# old format, so tests from here on may need --master-server-id. # old format, so tests from here on may need --master-server-id.
$master_dbh->do('drop table if exists test.heartbeat'); $master_dbh->do('drop table if exists test.heartbeat');
diag(`$cmd --update --run-time 1s --database test --table heartbeat --create-table`); $sb->wait_for_slaves;
$output = output(
sub { pt_heartbeat::main('-F', $cnf,
qw(--update --run-time 1s --database test --table heartbeat),
qw(--create-table)) },
stderr => 1,
);
$master_dbh->do('use test'); $master_dbh->do('use test');
$output = $master_dbh->selectcol_arrayref("SHOW TABLES LIKE 'heartbeat'"); $row = $master_dbh->selectcol_arrayref("SHOW TABLES LIKE 'heartbeat'");
is( is(
$output->[0], $row->[0],
'heartbeat', 'heartbeat',
'--create-table creates heartbeat table' '--create-table creates heartbeat table'
); ) or diag($output, Dumper($row));
# ############################################################################# # #############################################################################
# Issue 352: Add port to mk-heartbeat --check output # Issue 352: Add port to mk-heartbeat --check output
# ############################################################################# # #############################################################################
sleep 1; sleep 1;
$output = `$cmd --host 127.1 --user msandbox --password msandbox --port 12345 -D test --check --recurse 1 --master-server-id 12345`; $output = output(
sub { pt_heartbeat::main(
qw(--host 127.1 --user msandbox --password msandbox --port 12345),
qw(-D test --check --recurse 1 --master-server-id 12345)) },
stderr => 1,
);
like( like(
$output, $output,
qr/:12346\s+\d/, qr/:12346\s+\d/,
@@ -204,4 +244,5 @@ is(
diag(`rm $pid_file $sent_file 2>/dev/null`); diag(`rm $pid_file $sent_file 2>/dev/null`);
$sb->wipe_clean($master_dbh); $sb->wipe_clean($master_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit; exit;