mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-05-05 01:00:35 +08:00
Merge enable-version-check-by-default.
This commit is contained in:
+130
-138
@@ -25,12 +25,12 @@ my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
my $slave1_dbh = $sb->get_dbh_for('slave1');
|
||||
|
||||
my $vc = 'VersionCheck';
|
||||
local $ENV{PERCONA_FORCE_VERSION_CHECK} = 1;
|
||||
|
||||
sub test_v {
|
||||
my (%args) = @_;
|
||||
|
||||
my $items = $vc->parse_server_response(
|
||||
my $items = VersionCheck::parse_server_response(
|
||||
response => $args{response},
|
||||
);
|
||||
is_deeply(
|
||||
@@ -39,7 +39,7 @@ sub test_v {
|
||||
"$args{name} items"
|
||||
);
|
||||
|
||||
my $versions = $vc->get_versions(
|
||||
my $versions = VersionCheck::get_versions(
|
||||
items => $items,
|
||||
instances => [
|
||||
{
|
||||
@@ -119,9 +119,8 @@ test_v(
|
||||
},
|
||||
);
|
||||
|
||||
use File::Spec;
|
||||
{
|
||||
local $ENV{PATH} = File::Spec->catfile($ENV{PERCONA_TOOLKIT_BRANCH}, "bin") . ":$ENV{PATH}";
|
||||
local $ENV{PATH} = "$ENV{PATH}:$trunk/bin";
|
||||
test_v(
|
||||
name => "bin_version",
|
||||
response => "pt-archiver;bin_version\n",
|
||||
@@ -165,11 +164,15 @@ SKIP: {
|
||||
);
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# Version getters
|
||||
# #############################################################################
|
||||
|
||||
# I can't think of a way to make these 2 OS tests more specific
|
||||
# since the test env doesn't know what OS its running on. We
|
||||
# at least know that an OS should have these two things: a word
|
||||
# and version with at least major and minor numbers.
|
||||
my $os = $vc->get_os_version;
|
||||
my $os = VersionCheck::get_os_version();
|
||||
|
||||
like(
|
||||
$os,
|
||||
@@ -191,11 +194,24 @@ ok(
|
||||
"Newline stripped from OS"
|
||||
);
|
||||
|
||||
is(
|
||||
VersionCheck::get_perl_module_version(
|
||||
item => {
|
||||
item => 'DBD::mysql',
|
||||
type => 'perl_module_version',
|
||||
vars => [],
|
||||
},
|
||||
instances => [],
|
||||
),
|
||||
$DBD::mysql::VERSION,
|
||||
"get_perl_module_version(): DBD::mysql"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Validate items
|
||||
# #############################################################################
|
||||
|
||||
my $versions = $vc->get_versions(
|
||||
my $versions = VersionCheck::get_versions(
|
||||
items => {
|
||||
'Foo' => {
|
||||
item => 'Foo',
|
||||
@@ -226,9 +242,9 @@ if ( $master_dbh ) {
|
||||
(undef, $mysql_distro)
|
||||
= $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version_comment'");
|
||||
|
||||
(undef, $master_id) = VersionCheck::_generate_identifier(
|
||||
(undef, $master_id) = VersionCheck::get_instance_id(
|
||||
{ dbh => $master_dbh, dsn => { h => '127.1', P => 12345 }});
|
||||
(undef, $slave1_id) = VersionCheck::_generate_identifier(
|
||||
(undef, $slave1_id) = VersionCheck::get_instance_id(
|
||||
{ dbh => $slave1_dbh, dsn => { h => '127.1', P => 12346 }});
|
||||
|
||||
$master_inst = {
|
||||
@@ -281,7 +297,7 @@ sub test_pingback {
|
||||
eval {
|
||||
$sug = VersionCheck::pingback(
|
||||
url => $url,
|
||||
instances => $args{instances},
|
||||
instances => $args{instances} || [],
|
||||
ua => $fake_ua,
|
||||
);
|
||||
};
|
||||
@@ -290,7 +306,7 @@ sub test_pingback {
|
||||
eval {
|
||||
$sug = VersionCheck::pingback(
|
||||
url => $url,
|
||||
instances => $args{instances},
|
||||
instances => $args{instances} || [],
|
||||
ua => $fake_ua,
|
||||
);
|
||||
};
|
||||
@@ -463,86 +479,104 @@ SKIP: {
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# Testing time_to_check
|
||||
# get_instances_to_check()
|
||||
# #############################################################################
|
||||
|
||||
my $dir = File::Spec->tmpdir();
|
||||
my $file = File::Spec->catfile($dir, 'percona-toolkit-version-check-test');
|
||||
my $vc_file = VersionCheck::version_check_file();
|
||||
unlink $vc_file if -f $vc_file;
|
||||
PerconaTest::wait_until( sub { !-f $vc_file } );
|
||||
|
||||
unlink $file if -f $file;
|
||||
my $now = 100000; # a fake Unix ts works
|
||||
|
||||
my $time = int(time());
|
||||
my $instances = [];
|
||||
|
||||
sub get_check {
|
||||
my (%args) = @_;
|
||||
return VersionCheck::get_instances_to_check(
|
||||
instances => $instances,
|
||||
vc_file => $vc_file,
|
||||
now => $args{now} || $now,
|
||||
);
|
||||
}
|
||||
|
||||
my $check = get_check();
|
||||
|
||||
is_deeply(
|
||||
$check,
|
||||
[],
|
||||
"get_instances_to_check(): no instances"
|
||||
) or diag(Dumper($check));
|
||||
|
||||
ok(
|
||||
VersionCheck::time_to_check($file, [], $time),
|
||||
"time_to_check returns true if the file doesn't exist",
|
||||
!-f $vc_file,
|
||||
"Version check file not created"
|
||||
);
|
||||
|
||||
# Add default system instance. version_check() does this.
|
||||
push @$instances, { id => 0, name => "system" };
|
||||
|
||||
eval {
|
||||
VersionCheck::update_check_times(
|
||||
instances => $instances,
|
||||
vc_file => $vc_file,
|
||||
now => $now,
|
||||
);
|
||||
};
|
||||
|
||||
is(
|
||||
$EVAL_ERROR,
|
||||
"",
|
||||
"update_check_times(): no error"
|
||||
);
|
||||
|
||||
ok(
|
||||
!-f $file,
|
||||
"time_to_check doesn't create the checks file"
|
||||
-f $vc_file,
|
||||
"update_check_times() created version check file"
|
||||
);
|
||||
|
||||
VersionCheck::update_checks_file($file, [], $time);
|
||||
my $output = `cat $vc_file`;
|
||||
|
||||
ok(
|
||||
-f $file,
|
||||
"update_checks_file creates the checks file"
|
||||
is(
|
||||
$output,
|
||||
"0,$now\n",
|
||||
"Version check file contents"
|
||||
);
|
||||
|
||||
ok(
|
||||
!VersionCheck::time_to_check($file, [], $time),
|
||||
"time_to_check is false if file exists and it's been less than 24 hours"
|
||||
);
|
||||
$check = get_check();
|
||||
|
||||
my $one_day = 60 * 60 * 24;
|
||||
my ($orig_atime, $orig_mtime) = (stat($file))[8,9];
|
||||
is_deeply(
|
||||
$check,
|
||||
[],
|
||||
"get_instances_to_check(): no instances to check"
|
||||
) or diag(Dumper($check));
|
||||
|
||||
my $mod_atime = $orig_atime - $one_day * 2;
|
||||
my $mod_mtime = $orig_mtime - $one_day * 2;
|
||||
my $check_time_limit = VersionCheck::version_check_time_limit();
|
||||
|
||||
utime($mod_atime, $mod_mtime, $file);
|
||||
open my $fh, '>', $vc_file
|
||||
or die "Cannot write to $vc_file: $OS_ERROR";
|
||||
print { $fh } "0,$now\n";
|
||||
close $fh;
|
||||
|
||||
cmp_ok(
|
||||
(stat($file))[9],
|
||||
q{<},
|
||||
time() - $one_day,
|
||||
"The file's mtime is at least one day behind time()",
|
||||
);
|
||||
# You can verify this test by adding - 1 to this line,
|
||||
# making it seem like the instance hasn't been checked
|
||||
# in 1 second less than the limit.
|
||||
$check = get_check(now => $now + $check_time_limit);
|
||||
|
||||
ok(
|
||||
VersionCheck::time_to_check($file, [], $time),
|
||||
"time_to_check true if file exists and mtime < one day"
|
||||
);
|
||||
|
||||
my ($atime, $mtime) = (stat($file))[8,9];
|
||||
|
||||
is($mod_atime, $atime, "time_to_check doesn't update the atime");
|
||||
is($mod_mtime, $mtime, "time_to_check doesn't update the mtime");
|
||||
|
||||
VersionCheck::update_checks_file($file, [], $time);
|
||||
|
||||
($atime, $mtime) = (stat($file))[8,9];
|
||||
|
||||
ok(
|
||||
$orig_atime == $atime
|
||||
&& $orig_mtime == $mtime,
|
||||
"...but update_checks_file does"
|
||||
);
|
||||
|
||||
ok(
|
||||
!VersionCheck::time_to_check($file, [], $time),
|
||||
"...and time_to_check fails after update_checks_file"
|
||||
);
|
||||
is_deeply(
|
||||
$check,
|
||||
$instances,
|
||||
"get_instances_to_check(): time to check instance"
|
||||
) or diag(Dumper($check));
|
||||
|
||||
# #############################################################################
|
||||
# _generate_identifier
|
||||
# get_instance_id
|
||||
# #############################################################################
|
||||
|
||||
is(
|
||||
VersionCheck::_generate_identifier( { dbh => undef, dsn => { h => "localhost", P => 12345 } } ),
|
||||
VersionCheck::get_instance_id(
|
||||
{ dbh => undef, dsn => { h => "localhost", P => 12345 } } ),
|
||||
md5_hex("localhost", 12345),
|
||||
"_generate_identifier() works as expected for 4.1",
|
||||
"get_instance_id() works as expected for 4.1",
|
||||
);
|
||||
|
||||
SKIP: {
|
||||
@@ -564,91 +598,49 @@ SKIP: {
|
||||
else {
|
||||
$expect_master_id = md5_hex("localhost", 12345);
|
||||
}
|
||||
|
||||
|
||||
is(
|
||||
$master_id,
|
||||
$expect_master_id,
|
||||
"_generate_identifier() for MySQL $sandbox_version"
|
||||
"get_instance_id() for MySQL $sandbox_version"
|
||||
);
|
||||
|
||||
# The time limit file already exists (see previous tests), but this is
|
||||
# a new MySQL instance, so it should be time to check it.
|
||||
my ($is_time, $check_inst) = VersionCheck::time_to_check(
|
||||
$file,
|
||||
[ $master_inst ],
|
||||
);
|
||||
VersionCheck::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
$is_time,
|
||||
"Time to check a new MySQL instance ID",
|
||||
);
|
||||
push @$instances, $master_inst;
|
||||
$check = get_check();
|
||||
|
||||
is_deeply(
|
||||
$check_inst,
|
||||
$check,
|
||||
[ $master_inst ],
|
||||
"Check just the new instance"
|
||||
);
|
||||
"get_instances_to_check(): check new MySQL instance"
|
||||
) or diag(Dumper($check));
|
||||
|
||||
|
||||
($is_time, $check_inst) = VersionCheck::time_to_check(
|
||||
$file,
|
||||
[ $master_inst ],
|
||||
);
|
||||
|
||||
VersionCheck::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
!$is_time,
|
||||
"...but not the second time around",
|
||||
);
|
||||
|
||||
open my $fh, q{>}, $file or die $!;
|
||||
print { $fh } "$master_id," . (time() - $one_day * 2) . "\n";
|
||||
# Write vc file as if the system was checked now, but the MySQL
|
||||
# instance was checked 10 hours ago. So it won't need to checked
|
||||
# for another 14 hours.
|
||||
my $ten_hours = 60 * 60 * 10;
|
||||
my $fourteen_hours = 60 * 60 * 14;
|
||||
open my $fh, '>', $vc_file or die "Cannot write to $vc_file: $OS_ERROR";
|
||||
print { $fh } "0,$now\n$master_id," . ($now - $ten_hours) . "\n";
|
||||
close $fh;
|
||||
|
||||
($is_time, $check_inst) = VersionCheck::time_to_check(
|
||||
$file,
|
||||
[ $master_inst ],
|
||||
);
|
||||
$check = get_check();
|
||||
|
||||
VersionCheck::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
is_deeply(
|
||||
$check_inst,
|
||||
[ $master_inst ],
|
||||
"...unless more than a day has gone past",
|
||||
);
|
||||
$check,
|
||||
[],
|
||||
"get_instances_to_check(): not time to check either instance"
|
||||
) or diag(Dumper($check));
|
||||
|
||||
($is_time, $check_inst) = VersionCheck::time_to_check(
|
||||
$file,
|
||||
[ $master_inst, $slave1_inst ],
|
||||
);
|
||||
# Pretend like those 14 hours have passed now.
|
||||
$check = get_check(now => $now + $fourteen_hours);
|
||||
|
||||
VersionCheck::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
is_deeply(
|
||||
$check_inst,
|
||||
[ $slave1_inst ],
|
||||
"With multiple ids, time_to_check() returns only those that need checking",
|
||||
);
|
||||
|
||||
ok(
|
||||
$is_time,
|
||||
"...and is time to check"
|
||||
);
|
||||
|
||||
($is_time, $check_inst) = VersionCheck::time_to_check(
|
||||
$file,
|
||||
[ $master_inst, $slave1_inst ],
|
||||
);
|
||||
|
||||
VersionCheck::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
!$is_time,
|
||||
"...and false if there isn't anything to check",
|
||||
);
|
||||
$check,
|
||||
[ $master_inst ],
|
||||
"get_instances_to_check(): time to check one of two instances"
|
||||
) or diag(Dumper($check));
|
||||
}
|
||||
|
||||
# ############################################################################
|
||||
@@ -656,8 +648,8 @@ SKIP: {
|
||||
# if the file doesn't exist.
|
||||
# #############################################################################
|
||||
|
||||
unlink $file if -f $file;
|
||||
PerconaTest::wait_until( sub { !-f $file } );
|
||||
unlink $vc_file if -f $vc_file;
|
||||
PerconaTest::wait_until( sub { !-f $vc_file } );
|
||||
|
||||
SKIP: {
|
||||
skip 'Cannot connect to sandbox master', 2 unless $master_dbh;
|
||||
@@ -708,11 +700,11 @@ my @vc_tools = grep { chomp; basename($_) =~ /\A[a-z-]+\z/ }
|
||||
|
||||
foreach my $tool ( @vc_tools ) {
|
||||
my $tool_name = basename($tool);
|
||||
my $output = `$tool --version-check ftp`;
|
||||
my $output = `$tool --help`;
|
||||
like(
|
||||
$output,
|
||||
qr/\Q* --version-check invalid value ftp. Accepted values are https, http, auto and off/,
|
||||
"$tool_name validates --version-check"
|
||||
qr/^\s+--version-check\s+TRUE$/m,
|
||||
"--version-check is on in $tool_name"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,47 +32,60 @@ my $cnf = "/tmp/12345/my.sandbox.cnf";
|
||||
my $cmd = "$trunk/bin/pt-archiver";
|
||||
my @args = qw(--dry-run --where 1=1);
|
||||
|
||||
# Pingback.pm does this too.
|
||||
my $dir = File::Spec->tmpdir();
|
||||
my $check_time_file = File::Spec->catfile($dir,'percona-toolkit-version-check');
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
my $vc_file = VersionCheck::version_check_file();
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
$sb->create_dbs($master_dbh, ['test']);
|
||||
$sb->load_file('master', 't/pt-archiver/samples/tables1-4.sql');
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
# Normally --version-check is on by default, but in dev/testing envs,
|
||||
# there's going to be a .bzr dir that auto-disables --version-check so
|
||||
# our dev/test boxes don't flood the v-c database. Consequently,
|
||||
# have have to explicitly give --version-check to force the check.
|
||||
|
||||
$output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/(?:VersionCheck|Pingback|Percona suggests)/,
|
||||
qr/VersionCheck:\d+ \d+ Server response/,
|
||||
"Looks like the version-check happened"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
-f $vc_file,
|
||||
"Version check file was created"
|
||||
) or diag($output);
|
||||
|
||||
$rows = $master_dbh->selectall_arrayref("SELECT * FROM test.table_1");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[],
|
||||
"Tool ran after version-check"
|
||||
) or diag(Dumper($rows));
|
||||
|
||||
ok(
|
||||
-f $check_time_file,
|
||||
"Created percona-toolkit-version-check file"
|
||||
);
|
||||
) or diag(Dumper($rows), $output);
|
||||
|
||||
# ###########################################################################
|
||||
# v-c file should limit checks to 1 per 24 hours
|
||||
# ###########################################################################
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
my $orig_vc_file = `cat $vc_file 2>/dev/null`;
|
||||
|
||||
$output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/It is not time to --version-check again/,
|
||||
"Doesn't always check because of time limit"
|
||||
qr/0 instances to check/,
|
||||
"No instances to check because of time limit"
|
||||
);
|
||||
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
my $new_vc_file = `cat $vc_file 2>/dev/null`;
|
||||
|
||||
is(
|
||||
$new_vc_file,
|
||||
$orig_vc_file,
|
||||
"Version check file not changed"
|
||||
) or diag($output);
|
||||
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
# ###########################################################################
|
||||
# Fake v.percona.com not responding by using a different, non-existent URL.
|
||||
@@ -80,17 +93,17 @@ unlink $check_time_file if -f $check_time_file;
|
||||
|
||||
my $t0 = time;
|
||||
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
$output = `PTDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
|
||||
|
||||
my $t = time - $t0;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Error.+?(?:GET on http:\/\/x\.percona\.com.+?HTTP status 5\d+|Failed to get any program versions; should have at least gotten Perl)/,
|
||||
qr/Version check failed: GET on \S+x.percona.com returned HTTP status 5../,
|
||||
"The Percona server didn't respond"
|
||||
);
|
||||
|
||||
# In actuality it should only wait 2s, but on slow boxes all the other
|
||||
# In actuality it should only wait 3s, but on slow boxes all the other
|
||||
# stuff the tool does may cause the time to be much greater than 2.
|
||||
# If nothing else, this tests that the timeout isn't something crazy
|
||||
# like 30s.
|
||||
@@ -102,40 +115,77 @@ cmp_ok(
|
||||
);
|
||||
|
||||
# ###########################################################################
|
||||
# Disable the v-c (for now it's disabled by default, so by "disable" here
|
||||
# we just mean "don't pass --version-check").
|
||||
# Disable --version-check.
|
||||
# ###########################################################################
|
||||
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge 2>&1`;
|
||||
$output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --no-version-check 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/(?:VersionCheck|Pingback|Percona suggests)/,
|
||||
"Looks like no --version-check disabled the version-check"
|
||||
qr/VersionCheck/,
|
||||
"Looks like --no-version-check disabled the check"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
!-f $check_time_file,
|
||||
"percona-toolkit-version-check file not created with --no-version-check"
|
||||
);
|
||||
!-f $vc_file,
|
||||
"... version check file was not created"
|
||||
) or diag(`cat $vc_file`);
|
||||
|
||||
# PERCONA_VERSION_CHECK=0 is handled in Pingback, so it will print a line
|
||||
# for PTVCDEBUG saying why it didn't run. So we just check that it doesn't
|
||||
# create the file which also signifies that it didn't run.
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK=0 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
# Since this is a test, VersionCheck should detect the .bzr dir
|
||||
# and disble itself even without --no-version-check.
|
||||
|
||||
$output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/\.bzr disables --version-check/,
|
||||
"Looks like .bzr disabled the check"
|
||||
) or diag($output);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Updating last check time/,
|
||||
"... version check file was not updated"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
!-f $check_time_file,
|
||||
"Looks like PERCONA_VERSION_CHECK=0 disabled the version-check"
|
||||
);
|
||||
!-f $vc_file,
|
||||
"... version check file was not created"
|
||||
) or diag($output, `cat $vc_file`);
|
||||
|
||||
|
||||
# #############################################################################
|
||||
# Test --version-check as if tool isn't in a dev/test env by copying
|
||||
# to another dir so VersionCheck won't see a ../.bzr/.
|
||||
# #############################################################################
|
||||
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
diag(`cp $trunk/bin/pt-archiver /tmp/pt-archiver.$PID`);
|
||||
|
||||
# Notice: --version-check is NOT on the command line, because
|
||||
# it should be enabled by default.
|
||||
$output = `PTDEBUG=1 /tmp/pt-archiver.$PID --source F=$cnf,D=test,t=table_1 --where 1=1 --purge 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/VersionCheck:\d+ \d+ Server response/,
|
||||
"Looks like the version-check happened by default"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
-f $vc_file,
|
||||
"Version check file was created by default"
|
||||
) or diag($output);
|
||||
|
||||
unlink "/tmp/pt-archiver.$PID" if "/tmp/pt-archiver.$PID";
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
unlink $vc_file if -f $vc_file;
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
||||
@@ -10,57 +10,66 @@ use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use File::Spec::Functions;
|
||||
use Time::HiRes qw(time);
|
||||
use Data::Dumper;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use Data::Dumper;
|
||||
use File::Spec;
|
||||
use Time::HiRes qw(time);
|
||||
require "$trunk/bin/pt-query-digest";
|
||||
|
||||
my $output;
|
||||
my $cmd = catfile($trunk, "bin", "pt-query-digest");
|
||||
my @args = (qw(--limit 1), catfile($trunk, qw(t lib samples slowlogs slow001.txt)));
|
||||
my $cmd = "$trunk/bin/pt-query-digest --limit 1 $trunk/t/lib/samples/slowlogs/slow001.txt";
|
||||
|
||||
# Pingback.pm does this too.
|
||||
my $dir = File::Spec->tmpdir();
|
||||
my $check_time_file = File::Spec->catfile($dir,'percona-toolkit-version-check');
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
my $vc_file = VersionCheck::version_check_file();
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd @args --version-check http 2>&1`;
|
||||
# Normally --version-check is on by default, but in dev/testing envs,
|
||||
# there's going to be a .bzr dir that auto-disables --version-check so
|
||||
# our dev/test boxes don't flood the v-c database. Consequently,
|
||||
# have have to explicitly give --version-check to force the check.
|
||||
|
||||
$output = `PTDEBUG=1 $cmd --version-check 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/(?:VersionCheck|Pingback|Percona suggests)/,
|
||||
qr/VersionCheck:\d+ \d+ Server response/,
|
||||
"Looks like the version-check happened"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
-f $vc_file,
|
||||
"Version check file was created"
|
||||
) or diag($output);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/# Query 1: 0 QPS, 0x concurrency, ID 0x7F7D57ACDD8A346E at byte 0/,
|
||||
"Tool ran after version-check"
|
||||
) or diag(Dumper($output));
|
||||
|
||||
ok(
|
||||
-f $check_time_file,
|
||||
"Created percona-toolkit-version-check file"
|
||||
);
|
||||
|
||||
# ###########################################################################
|
||||
# v-c file should limit checks to 1 per 24 hours
|
||||
# ###########################################################################
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd @args --version-check http 2>&1`;
|
||||
my $orig_vc_file = `cat $vc_file 2>/dev/null`;
|
||||
|
||||
$output = `PTDEBUG=1 $cmd --version-check 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/It is not time to --version-check again/,
|
||||
"Doesn't always check because of time limit"
|
||||
qr/0 instances to check/,
|
||||
"No instances to check because of time limit"
|
||||
);
|
||||
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
my $new_vc_file = `cat $vc_file 2>/dev/null`;
|
||||
|
||||
is(
|
||||
$new_vc_file,
|
||||
$orig_vc_file,
|
||||
"Version check file not changed"
|
||||
) or diag($output);
|
||||
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
# ###########################################################################
|
||||
# Fake v.percona.com not responding by using a different, non-existent URL.
|
||||
@@ -68,17 +77,17 @@ unlink $check_time_file if -f $check_time_file;
|
||||
|
||||
my $t0 = time;
|
||||
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd @args --version-check http 2>&1`;
|
||||
$output = `PTDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd --version-check 2>&1`;
|
||||
|
||||
my $t = time - $t0;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Error.+?(?:GET on http:\/\/x\.percona\.com.+?HTTP status 5\d+|Failed to get any program versions; should have at least gotten Perl)/,
|
||||
qr/Version check failed: GET on \S+x.percona.com returned HTTP status 5../,
|
||||
"The Percona server didn't respond"
|
||||
);
|
||||
|
||||
# In actuality it should only wait 2s, but on slow boxes all the other
|
||||
# In actuality it should only wait 3s, but on slow boxes all the other
|
||||
# stuff the tool does may cause the time to be much greater than 2.
|
||||
# If nothing else, this tests that the timeout isn't something crazy
|
||||
# like 30s.
|
||||
@@ -90,51 +99,75 @@ cmp_ok(
|
||||
);
|
||||
|
||||
# ###########################################################################
|
||||
# Disable the v-c (for now it's disabled by default, so by "disable" here
|
||||
# we just mean "don't pass --version-check").
|
||||
# Disable --version-check.
|
||||
# ###########################################################################
|
||||
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd @args 2>&1`;
|
||||
$output = `PTDEBUG=1 $cmd --no-version-check 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/(?:VersionCheck|Pingback|Percona suggests)/,
|
||||
"Looks like --no-version-check disabled the version-check"
|
||||
qr/VersionCheck/,
|
||||
"Looks like --no-version-check disabled the check"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
!-f $check_time_file,
|
||||
"percona-toolkit-version-check file not created with --no-version-check"
|
||||
);
|
||||
!-f $vc_file,
|
||||
"... version check file was not created"
|
||||
) or diag(`cat $vc_file`);
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --version-check off @args 2>&1`;
|
||||
# Since this is a test, VersionCheck should detect the .bzr dir
|
||||
# and disble itself even without --no-version-check.
|
||||
|
||||
$output = `PTDEBUG=1 $cmd 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/\.bzr disables --version-check/,
|
||||
"Looks like .bzr disabled the check"
|
||||
) or diag($output);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/(?:VersionCheck|Pingback|Percona suggests)/,
|
||||
"Looks like --version-check off disabled the version-check"
|
||||
qr/Updating last check time/,
|
||||
"... version check file was not updated"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
!-f $check_time_file,
|
||||
"percona-toolkit-version-check file not created with --version-check off"
|
||||
);
|
||||
!-f $vc_file,
|
||||
"... version check file was not created"
|
||||
) or diag($output, `cat $vc_file`);
|
||||
|
||||
# PERCONA_VERSION_CHECK=0 is handled in Pingback, so it will print a line
|
||||
# for PTVCDEBUG saying why it didn't run. So we just check that it doesn't
|
||||
# create the file which also signifies that it didn't run.
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK=0 $cmd @args --version-check http 2>&1`;
|
||||
|
||||
# #############################################################################
|
||||
# Test --version-check as if tool isn't in a dev/test env by copying
|
||||
# to another dir so VersionCheck won't see a ../.bzr/.
|
||||
# #############################################################################
|
||||
|
||||
unlink $vc_file if -f $vc_file;
|
||||
|
||||
diag(`cp $trunk/bin/pt-query-digest /tmp/pt-query-digest.$PID`);
|
||||
|
||||
# Notice: --version-check is NOT on the command line, because
|
||||
# it should be enabled by default.
|
||||
$output = `PTDEBUG=1 /tmp/pt-query-digest.$PID --limit 1 $trunk/t/lib/samples/slowlogs/slow001.txt 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/VersionCheck:\d+ \d+ Server response/,
|
||||
"Looks like the version-check happened by default"
|
||||
) or diag($output);
|
||||
|
||||
ok(
|
||||
!-f $check_time_file,
|
||||
"Looks like PERCONA_VERSION_CHECK=0 disabled the version-check"
|
||||
);
|
||||
-f $vc_file,
|
||||
"Version check file was created by default"
|
||||
) or diag($output);
|
||||
|
||||
unlink "/tmp/pt-query-digest.$PID" if "/tmp/pt-query-digest.$PID";
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
unlink $vc_file if -f $vc_file;
|
||||
done_testing;
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user