tests: increase sws timeout for more robust testing

- for https CONNECT forwarding, this was fixed at 5 seconds
  which led to spurious CI test failures
- add --keepalive parameter to sws to control this
- let httpserver use 30 seconds

Closes #10898
This commit is contained in:
Stefan Eissing 2023-04-06 11:19:46 +02:00 committed by Daniel Stenberg
parent 632e0fbe70
commit 356dd0b73a
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 37 additions and 7 deletions

View File

@ -53,6 +53,7 @@ my $portfile; # port number file
my $logfile; # log file
my $cmdfile; # command file
my $connect; # IP to connect to on CONNECT
my $keepalive_secs; # number of seconds to keep idle connections
my $srcdir;
my $gopher = 0;
@ -126,6 +127,12 @@ while(@ARGV) {
shift @ARGV;
}
}
elsif($ARGV[0] eq '--keepalive') {
if($ARGV[1]) {
$keepalive_secs = $ARGV[1];
shift @ARGV;
}
}
elsif($ARGV[0] eq '--id') {
if($ARGV[1] =~ /^(\d+)$/) {
$idnum = $1 if($1 > 0);
@ -171,6 +178,7 @@ $flags .= "--pidfile \"$pidfile\" ".
"--portfile \"$portfile\" ";
$flags .= "--gopher " if($gopher);
$flags .= "--connect $connect " if($connect);
$flags .= "--keepalive $keepalive_secs " if($keepalive_secs);
if($ipvnum eq 'unix') {
$flags .= "--unix-socket '$unix_socket' ";
} else {

View File

@ -1552,6 +1552,8 @@ sub runhttpserver {
my $idnum = 1;
my $exe = "$perl $srcdir/http-server.pl";
my $verbose_flag = "--verbose ";
my $keepalive_secs = 30; # forwarded to sws, was 5 by default which
# led to pukes in CI jobs
if($alt eq "ipv6") {
# if IPv6, use a different setup
@ -1590,6 +1592,7 @@ sub runhttpserver {
my $flags = "";
$flags .= "--gopher " if($proto eq "gopher");
$flags .= "--connect $HOSTIP " if($alt eq "proxy");
$flags .= "--keepalive $keepalive_secs ";
$flags .= $verbose_flag if($debugprotocol);
$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
$flags .= "--logdir \"$LOGDIR\" ";

View File

@ -146,8 +146,8 @@ static void storerequest(const char *reqbuf, size_t totalsize);
#endif
const char *serverlogfile = DEFAULT_LOGFILE;
const char *logdir = "log";
char loglockfile[256];
static const char *logdir = "log";
static char loglockfile[256];
#define SWSVERSION "curl test suite HTTP server/0.1"
@ -1391,7 +1391,8 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
static void http_connect(curl_socket_t *infdp,
curl_socket_t rootfd,
const char *ipaddr,
unsigned short ipport)
unsigned short ipport,
int keepalive_secs)
{
curl_socket_t serverfd[2] = {CURL_SOCKET_BAD, CURL_SOCKET_BAD};
curl_socket_t clientfd[2] = {CURL_SOCKET_BAD, CURL_SOCKET_BAD};
@ -1747,7 +1748,7 @@ static void http_connect(curl_socket_t *infdp,
} /* (rc > 0) */
else {
timeout_count++;
if(timeout_count > 5) {
if(timeout_count > keepalive_secs) {
logmsg("CONNECT proxy timeout after %d idle seconds!", timeout_count);
break;
}
@ -1867,7 +1868,8 @@ static curl_socket_t accept_connection(curl_socket_t sock)
is no data waiting, or < 0 if it should be closed */
static int service_connection(curl_socket_t msgsock, struct httprequest *req,
curl_socket_t listensock,
const char *connecthost)
const char *connecthost,
int keepalive_secs)
{
if(got_exit_signal)
return -1;
@ -1914,7 +1916,8 @@ static int service_connection(curl_socket_t msgsock, struct httprequest *req,
return 1;
}
else {
http_connect(&msgsock, listensock, connecthost, req->connect_port);
http_connect(&msgsock, listensock, connecthost, req->connect_port,
keepalive_secs);
return -1;
}
}
@ -1960,6 +1963,7 @@ int main(int argc, char *argv[])
const char *socket_type = "IPv4";
char port_str[11];
const char *location_str = port_str;
int keepalive_secs = 5;
/* a default CONNECT port is basically pointless but still ... */
size_t socket_idx;
@ -2059,6 +2063,21 @@ int main(int argc, char *argv[])
arg++;
}
}
else if(!strcmp("--keepalive", argv[arg])) {
arg++;
if(argc>arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
if((endptr != argv[arg] + strlen(argv[arg])) ||
(ulnum && ((ulnum < 0UL) || (ulnum > 65535UL)))) {
fprintf(stderr, "sws: invalid --keepalive argument (%s), must "
"be number of seconds\n", argv[arg]);
return 0;
}
keepalive_secs = curlx_ultous(ulnum);
arg++;
}
}
else if(!strcmp("--connect", argv[arg])) {
/* The connect host IP number that the proxy will connect to no matter
what the client asks for, but also use this as a hint that we run as
@ -2320,7 +2339,7 @@ int main(int argc, char *argv[])
/* Service this connection until it has nothing available */
do {
rc = service_connection(all_sockets[socket_idx], req, sock,
connecthost);
connecthost, keepalive_secs);
if(got_exit_signal)
goto sws_cleanup;