diff --git a/lib/BackRest/Backup.pm b/lib/BackRest/Backup.pm index 0224d019e..ad16cdf38 100644 --- a/lib/BackRest/Backup.pm +++ b/lib/BackRest/Backup.pm @@ -219,7 +219,7 @@ sub backup_thread_complete } # Sleep before trying again - sleep(.1); + hsleep(.1); } &log(DEBUG, 'all threads exited'); diff --git a/lib/BackRest/ThreadGroup.pm b/lib/BackRest/ThreadGroup.pm index e816f5694..aba5798b2 100644 --- a/lib/BackRest/ThreadGroup.pm +++ b/lib/BackRest/ThreadGroup.pm @@ -8,16 +8,10 @@ use strict; use warnings; use Carp; -# use Scalar::Util; -# use Net::OpenSSH; use File::Basename; -# use POSIX ':sys_wait_h'; -# use Scalar::Util 'blessed'; -# + use lib dirname($0) . '/../lib'; -# use BackRest::Exception; use BackRest::Utility; -# use BackRest::ProcessAsync; #################################################################################################################################### # CONSTRUCTOR @@ -73,7 +67,7 @@ sub complete # Rejoin the threads while ($iThreadComplete < $self->{iThreadTotal}) { - sleep(.1); + hsleep(.1); # If a timeout has been defined, make sure we have not been running longer than that if (defined($iTimeout)) diff --git a/lib/BackRest/Utility.pm b/lib/BackRest/Utility.pm index 26ee181c4..6c6bfc767 100644 --- a/lib/BackRest/Utility.pm +++ b/lib/BackRest/Utility.pm @@ -10,6 +10,7 @@ use Carp qw(confess longmess); use Fcntl qw(:DEFAULT :flock); use File::Path qw(remove_tree); +use Time::HiRes qw(usleep); use File::Basename; use JSON; @@ -21,7 +22,7 @@ use Exporter qw(import); our @EXPORT = qw(version_get data_hash_build trim common_prefix wait_for_file file_size_format execute log log_file_set log_level_set test_set test_get test_check - lock_file_create lock_file_remove + lock_file_create lock_file_remove hsleep ini_save ini_load timestamp_string_get timestamp_file_string_get TRACE DEBUG ERROR ASSERT WARN INFO OFF true false TEST TEST_ENCLOSE TEST_MANIFEST_BUILD TEST_BACKUP_RESUME TEST_BACKUP_NORESUME); @@ -75,7 +76,7 @@ use constant # Test global variables my $bTest = false; -my $iTestDelay; +my $fTestDelay; #################################################################################################################################### # VERSION_GET @@ -212,6 +213,16 @@ sub trim return $strBuffer; } +#################################################################################################################################### +# hsleep - wrapper for usleep that takes seconds in fractions and returns time slept in ms +#################################################################################################################################### +sub hsleep +{ + my $fSecond = shift; + + return usleep($fSecond * 1000000); +} + #################################################################################################################################### # WAIT_FOR_FILE #################################################################################################################################### @@ -237,7 +248,7 @@ sub wait_for_file return; } - sleep(1); + hsleep(.1); } confess &log(ERROR, "could not find $strDir/$strRegEx after ${iSeconds} second(s)"); @@ -359,20 +370,20 @@ sub log_file_set sub test_set { my $bTestParam = shift; - my $iTestDelayParam = shift; + my $fTestDelayParam = shift; # Set defaults $bTest = defined($bTestParam) ? $bTestParam : false; - $iTestDelay = defined($bTestParam) ? $iTestDelayParam : $iTestDelay; + $fTestDelay = defined($bTestParam) ? $fTestDelayParam : $fTestDelay; # Make sure that a delay is specified in test mode - if ($bTest && !defined($iTestDelay)) + if ($bTest && !defined($fTestDelay)) { confess &log(ASSERT, 'iTestDelay must be provided when bTest is true'); } # Test delay should be between 1 and 600 seconds - if (!($iTestDelay >= 0 && $iTestDelay <= 600)) + if (!($fTestDelay >= 0 && $fTestDelay <= 600)) { confess &log(ERROR, 'test-delay must be between 1 and 600 seconds'); } @@ -498,9 +509,9 @@ sub log { *STDOUT->flush(); - if ($iTestDelay > 0) + if ($fTestDelay > 0) { - sleep($iTestDelay); + hsleep($fTestDelay); } } } diff --git a/test/lib/BackRestTest/BackupTest.pm b/test/lib/BackRestTest/BackupTest.pm index aa2447f48..80dabe8b2 100755 --- a/test/lib/BackRestTest/BackupTest.pm +++ b/test/lib/BackRestTest/BackupTest.pm @@ -15,8 +15,8 @@ use File::Basename; use File::Copy 'cp'; use File::stat; use Fcntl ':mode'; +use Time::HiRes qw(gettimeofday); use DBI; -use Time::HiRes qw(gettimeofday usleep); use lib dirname($0) . '/../lib'; use BackRest::Exception; @@ -999,7 +999,7 @@ sub BackRestTestBackup_Test if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck)) { - sleep(1); + hsleep(1); if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck)) { @@ -1644,7 +1644,7 @@ sub BackRestTestBackup_Test # Sleep .5 seconds to give a reasonable amount of time for the file to be copied after the manifest was generated # Sleep for a while to show there is a large window where this can happen &log(INFO, 'time ' . gettimeofday()); - usleep(.5 * 1000000); + hsleep(.5); &log(INFO, 'time ' . gettimeofday()); # Insert another row @@ -1736,7 +1736,7 @@ sub BackRestTestBackup_Test # Sleep for a while to show there is a large window where this can happen &log(INFO, 'time ' . gettimeofday()); - usleep(.5 * 1000000); + hsleep(.5); &log(INFO, 'time ' . gettimeofday()); # Modify the test file within the same second