Make pt-archiver tests more reliable on weird, slow boxes like my vbox.

This commit is contained in:
Daniel Nichter
2011-07-14 09:57:16 -06:00
parent c78beba647
commit db76b3ca30
9 changed files with 38 additions and 106 deletions

View File

@@ -34,7 +34,7 @@ use English qw(-no_match_vars);
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
use Test::More;
use Time::HiRes qw(usleep);
use Time::HiRes qw(sleep);
use POSIX qw(signal_h);
use Data::Dumper;
$Data::Dumper::Indent = 1;
@@ -219,15 +219,14 @@ sub parse_file {
# Wait until code returns true.
sub wait_until {
my ( $code, $t, $max_t ) = @_;
my $slept = 0;
my $sleep_int = $t || .5;
$t ||= .5;
$max_t ||= 5;
$t *= 1_000_000;
$max_t ||= 10;
my $slept = 0;
while ( $slept <= $max_t ) {
return if $code->();
usleep($t);
$slept += $sleep_int;
sleep $t;
$slept += $t;
}
return;
}
@@ -255,6 +254,19 @@ sub wait_for {
return 0;
}
sub wait_for_table {
my ($dbh, $tbl) = @_;
return wait_until(
sub {
my $r;
eval { $r = $dbh->selectrow_arrayref("SELECT 1 FROM $tbl"); };
return $EVAL_ERROR ? 0 : 1;
},
0.25,
15,
);
}
sub _read {
my ( $fh ) = @_;
return <$fh>;