[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 236/282: tests: try to make sleeping portable by avoiding select
From: |
gnunet |
Subject: |
[gnurl] 236/282: tests: try to make sleeping portable by avoiding select |
Date: |
Wed, 01 Apr 2020 14:31:41 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 9aaca09044de4d4116822f25d2cf9c780d7465ce
Author: Marc Hoersken <address@hidden>
AuthorDate: Wed Mar 4 11:44:49 2020 +0100
tests: try to make sleeping portable by avoiding select
select does not support just waiting on Windows:
https://perldoc.perl.org/perlport.html#select
Reviewed-By: Daniel Stenberg
Closes #5035
---
tests/ftp.pm | 33 +++++++++++++++++++++++++++++++--
tests/ftpserver.pl | 6 +++---
tests/runtests.pl | 6 +++---
3 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/tests/ftp.pm b/tests/ftp.pm
index f4a4acedd..f7298bce6 100644
--- a/tests/ftp.pm
+++ b/tests/ftp.pm
@@ -5,7 +5,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 1998 - 2010, Daniel Stenberg, <address@hidden>, et al.
+# Copyright (C) 1998 - 2020, Daniel Stenberg, <address@hidden>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@@ -20,6 +20,14 @@
#
###########################################################################
+BEGIN {
+ # portable sleeping needs Time::HiRes
+ eval {
+ no warnings "all";
+ require Time::HiRes;
+ }
+}
+
use strict;
use warnings;
@@ -29,6 +37,27 @@ use serverhelp qw(
datasockf_pidfilename
);
+#######################################################################
+# portable_sleep uses Time::HiRes::sleep if available and falls back
+# to the classic approach of using select(undef, undef, undef, ...).
+# even though that one is not portable due to being implemented using
+# select on Windows: https://perldoc.perl.org/perlport.html#select
+# On Windows it also just uses full-second sleep for waits >1 second.
+#
+sub portable_sleep {
+ my ($seconds) = @_;
+
+ if($Time::HiRes::VERSION) {
+ Time::HiRes::sleep($seconds);
+ }
+ elsif ($seconds > 1 && ($^O eq 'MSWin32' || $^O eq 'msys')) {
+ sleep($seconds);
+ }
+ else {
+ select(undef, undef, undef, $seconds);
+ }
+}
+
#######################################################################
# pidfromfile returns the pid stored in the given pidfile. The value
# of the returned pid will never be a negative value. It will be zero
@@ -216,7 +245,7 @@ sub killpid {
}
}
last if(not scalar(@signalled));
- select(undef, undef, undef, 0.05);
+ portable_sleep(0.05);
}
}
diff --git a/tests/ftpserver.pl b/tests/ftpserver.pl
index 63dc3342c..431bd2586 100755
--- a/tests/ftpserver.pl
+++ b/tests/ftpserver.pl
@@ -493,7 +493,7 @@ sub sendcontrol {
for(@a) {
sockfilt $_;
- select(undef, undef, undef, 0.01);
+ portable_sleep(0.01);
}
}
my $log;
@@ -530,7 +530,7 @@ sub senddata {
# pause between each byte
for (split(//,$l)) {
sockfiltsecondary $_;
- select(undef, undef, undef, 0.01);
+ portable_sleep(0.01);
}
}
}
@@ -3199,7 +3199,7 @@ while(1) {
logmsg("Sleep for $delay seconds\n");
my $twentieths = $delay * 20;
while($twentieths--) {
- select(undef, undef, undef, 0.05) unless($got_exit_signal);
+ portable_sleep(0.05) unless($got_exit_signal);
}
}
diff --git a/tests/runtests.pl b/tests/runtests.pl
index 3306de397..7a5f8a504 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -482,7 +482,7 @@ sub startnew {
logmsg "startnew: failed to write fake $pidfile with pid=$child\n";
}
# could/should do a while connect fails sleep a bit and loop
- sleep $timeout;
+ portable_sleep($timeout);
if (checkdied($child)) {
logmsg "startnew: child process has failed to start\n"
if($verbose);
return (-1,-1);
@@ -3823,7 +3823,7 @@ sub singletest {
if($serverlogslocktimeout) {
my $lockretry = $serverlogslocktimeout * 20;
while((-f $SERVERLOGS_LOCK) && $lockretry--) {
- select(undef, undef, undef, 0.05);
+ portable_sleep(0.05);
}
if(($lockretry < 0) &&
($serverlogslocktimeout >= $defserverlogslocktimeout)) {
@@ -3840,7 +3840,7 @@ sub singletest {
# based tests might need a small delay once that the client command has
# run to avoid false test failures.
- sleep($postcommanddelay) if($postcommanddelay);
+ portable_sleep($postcommanddelay) if($postcommanddelay);
# timestamp removal of server logs advisor read lock
$timesrvrlog{$testnum} = Time::HiRes::time();
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [gnurl] 218/282: sha256: Added GNU TLS gcrypt implementation, (continued)
- [gnurl] 218/282: sha256: Added GNU TLS gcrypt implementation, gnunet, 2020/04/01
- [gnurl] 215/282: curl_getenv.3: Fix the memory handling description, gnunet, 2020/04/01
- [gnurl] 211/282: http: mark POSTs with no body as "upload done" from the start, gnunet, 2020/04/01
- [gnurl] 212/282: multi_wait: stop loop when sread() returns zero, gnunet, 2020/04/01
- [gnurl] 227/282: ci/tests: Move CI test result creation above environment setup, gnunet, 2020/04/01
- [gnurl] 228/282: README.md: add Azure DevOps Pipelines build status badge, gnunet, 2020/04/01
- [gnurl] 230/282: cmake: Show HTTPS-proxy in the features output, gnunet, 2020/04/01
- [gnurl] 226/282: ci/tests: Send test results to AppVeyor for status overview, gnunet, 2020/04/01
- [gnurl] 231/282: ci/tests: fix escaping of testnames and disable proxy for CI APIs, gnunet, 2020/04/01
- [gnurl] 237/282: tests: align some Windows sleep defines with each other, gnunet, 2020/04/01
- [gnurl] 236/282: tests: try to make sleeping portable by avoiding select,
gnunet <=
- [gnurl] 233/282: RELEASE-NOTES: 7.69.0, gnunet, 2020/04/01
- [gnurl] 244/282: urldata: remove the 'stream_was_rewound' connectdata struct member, gnunet, 2020/04/01
- [gnurl] 229/282: ci/tests: Make it possible to still run but ignore failing tests, gnunet, 2020/04/01
- [gnurl] 235/282: runtests.1: rephrase how to specify what tests to run, gnunet, 2020/04/01
- [gnurl] 241/282: MANUAL: update a dict-using command line, gnunet, 2020/04/01
- [gnurl] 232/282: THANKS: from 7.69.0, gnunet, 2020/04/01
- [gnurl] 245/282: transfer: set correct copyright year range, gnunet, 2020/04/01
- [gnurl] 239/282: polarssl: remove more references and mentions, gnunet, 2020/04/01
- [gnurl] 242/282: RELEASE-NOTES: synced, gnunet, 2020/04/01
- [gnurl] 248/282: pause: return early for calls that don't change pause state, gnunet, 2020/04/01