Skip to content

Commit

Permalink
Clean & harden normal tests (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
benrubson committed Mar 4, 2020
1 parent b60939c commit f2c4a16
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 336 deletions.
26 changes: 22 additions & 4 deletions integration/common.pl
Expand Up @@ -63,17 +63,35 @@ sub sizeVerify
return $ok;
}

# Wait for a file to appear
# Helper to check a file's content
sub checkContents
{
my ($file, $expected, $testName) = @_;

open(IN, "< $file");
my $line = <IN>;
is($line, $expected, $testName);

close IN;
}

# Wait for a file to (dis)appear
use Time::HiRes qw(usleep);
sub waitForFile
{
my $file = shift;
my $timeout;
$timeout = shift or $timeout = 5;
for(my $i = $timeout*10; $i > 0; $i--)
my $gone;
$gone = shift or $gone = 0;
for(my $i = $timeout*2; $i > 0; $i--)
{
-f $file and return 1;
usleep(100000); # 0.1 seconds
if (-f $file) {
($gone == 0) and return 1;
} elsif ($gone == 1) {
return 1;
}
usleep(500000); # 0.5 seconds
}
print "# timeout waiting for '$file' to appear\n";
return 0;
Expand Down

0 comments on commit f2c4a16

Please sign in to comment.