mirror of
https://github.com/curl/curl.git
synced 2026-08-24 21:53:37 +03:00
tests: improve server start reliability
Fix all lookups of the port a server is using by - unlinking the portfile before the start - waiting `timeout` seconds for the port file to exist and contain a positive number - check results and fail server start when port could not be determined Closes #17516
This commit is contained in:
parent
e61c287e73
commit
04c3895ceb
2 changed files with 73 additions and 22 deletions
|
|
@ -94,12 +94,18 @@ sub portable_sleep {
|
|||
#
|
||||
sub pidfromfile {
|
||||
my $pidfile = $_[0];
|
||||
my $timeout_sec = $_[1];
|
||||
my $pid = 0;
|
||||
|
||||
if(-f $pidfile && -s $pidfile && open(my $pidfh, "<", "$pidfile")) {
|
||||
$pid = 0 + <$pidfh>;
|
||||
close($pidfh);
|
||||
$pid = 0 if($pid < 0);
|
||||
my $waits = 0;
|
||||
# wait at max 15 seconds for the file to exist and have valid content
|
||||
while(!$pid && ($waits <= ($timeout_sec * 10))) {
|
||||
if(-f $pidfile && -s $pidfile && open(my $pidfh, "<", "$pidfile")) {
|
||||
$pid = 0 + <$pidfh>;
|
||||
close($pidfh);
|
||||
$pid = 0 if($pid < 0);
|
||||
}
|
||||
Time::HiRes::sleep(0.1) unless $pid || !$timeout_sec;
|
||||
++$waits;
|
||||
}
|
||||
return $pid;
|
||||
}
|
||||
|
|
@ -250,7 +256,7 @@ sub processexists {
|
|||
my $pidfile = $_[0];
|
||||
|
||||
# fetch pid from pidfile
|
||||
my $pid = pidfromfile($pidfile);
|
||||
my $pid = pidfromfile($pidfile, 0);
|
||||
|
||||
if($pid > 0) {
|
||||
# verify if currently alive
|
||||
|
|
@ -259,7 +265,7 @@ sub processexists {
|
|||
}
|
||||
else {
|
||||
# get rid of the certainly invalid pidfile
|
||||
unlink($pidfile) if($pid == pidfromfile($pidfile));
|
||||
unlink($pidfile) if($pid == pidfromfile($pidfile, 0));
|
||||
# reap its dead children, if not done yet
|
||||
pidwait($pid, &WNOHANG);
|
||||
# negative return value means dead process
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue