1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Decrease the posibility of aborting a test which actually is not

stale by replacing loop counters with timeouts. In this way the
main loop of the test will be allowed to run up to 30 seconds on
any platform before aborting it.
This commit is contained in:
Yang Tse 2006-10-20 15:39:54 +00:00
parent bd5d21aaf2
commit b9ccecf86e
8 changed files with 253 additions and 64 deletions

View File

@ -3,6 +3,11 @@
#include <sys/time.h>
#include <sys/types.h>
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
/*
* Source code in here hugely as reported in bug report 651464 by
* Christopher R. Palmer.
@ -20,8 +25,10 @@ int test(char *URL)
int running;
int max_fd;
int rc;
int loop1 = 10;
int loop2 = 20;
struct timeval ml_start;
struct timeval mp_start;
char ml_timedout = FALSE;
char mp_timedout = FALSE;
curl_global_init(CURL_GLOBAL_ALL);
c = curl_easy_init();
@ -38,19 +45,36 @@ int test(char *URL)
if(res && (res != CURLM_CALL_MULTI_PERFORM))
; /* major failure */
else {
ml_timedout = FALSE;
ml_start = curlx_tvnow();
do {
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
if (curlx_tvdiff(curlx_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
fprintf(stderr, "curl_multi_perform()\n");
mp_timedout = FALSE;
mp_start = curlx_tvnow();
do {
res = curl_multi_perform(m, &running);
} while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM));
if (loop2 <= 0)
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
} while (res == CURLM_CALL_MULTI_PERFORM);
if (mp_timedout)
break;
if(!running) {
/* This is where this code is expected to reach */
@ -84,11 +108,10 @@ int test(char *URL)
rc = select_test(max_fd+1, &rd, &wr, &exc, &interval);
fprintf(stderr, "select returned %d\n", rc);
/* we only allow a certain number of loops to avoid hanging here
forever */
} while(--loop1>0);
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "loop1: %d loop2: %d \n", loop1, loop2);
} while(1);
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
ret = 77;

View File

@ -1,5 +1,10 @@
#include "test.h"
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
int test(char *URL)
{
CURL* curls;
@ -7,8 +12,11 @@ int test(char *URL)
int still_running;
int i = -1;
CURLMsg *msg;
int loop1 = 20;
int loop2 = 40;
CURLMcode res;
struct timeval ml_start;
struct timeval mp_start;
char ml_timedout = FALSE;
char mp_timedout = FALSE;
multi = curl_multi_init();
@ -16,21 +24,41 @@ int test(char *URL)
curl_easy_setopt(curls, CURLOPT_URL, URL);
curl_multi_add_handle(multi, curls);
while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM ==
curl_multi_perform(multi, &still_running)));
mp_timedout = FALSE;
mp_start = curlx_tvnow();
while ((loop1>0) && (--loop2>0) && (still_running)) {
do {
res = curl_multi_perform(multi, &still_running);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
} while (res == CURLM_CALL_MULTI_PERFORM);
ml_timedout = FALSE;
ml_start = curlx_tvnow();
while ((!ml_timedout) && (!mp_timedout) && (still_running)) {
struct timeval timeout;
int rc;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if (curlx_tvdiff(curlx_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
rc = select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
switch(rc) {
@ -38,14 +66,22 @@ int test(char *URL)
break;
case 0:
default:
loop1 = 20;
while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM ==
curl_multi_perform(multi, &still_running)));
mp_timedout = FALSE;
mp_start = curlx_tvnow();
do {
res = curl_multi_perform(multi, &still_running);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
} while (res == CURLM_CALL_MULTI_PERFORM);
break;
}
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "loop1: %d loop2: %d \n", loop1, loop2);
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
i = 77;

View File

@ -18,6 +18,11 @@
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
int portnum; /* the HTTPS port number we use */
typedef struct sslctxparm_st {
@ -175,8 +180,10 @@ int test(char *URL)
int i = 0;
CURLMsg *msg;
int loop1 = 40;
int loop2 = 20;
struct timeval ml_start;
struct timeval mp_start;
char ml_timedout = FALSE;
char mp_timedout = FALSE;
if(arg2) {
portnum = atoi(arg2);
@ -208,24 +215,39 @@ int test(char *URL)
res = curl_multi_add_handle(multi, p.curl);
while ((--loop1>0) && (loop2>0) && (!done)) {
ml_timedout = FALSE;
ml_start = curlx_tvnow();
while (!done) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
if (curlx_tvdiff(curlx_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
mp_timedout = FALSE;
mp_start = curlx_tvnow();
while (res == CURLM_CALL_MULTI_PERFORM) {
res = curl_multi_perform(multi, &running);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
fprintf(stderr, "running=%d res=%d\n",running,res);
if (running <= 0) {
done = TRUE;
break;
}
}
if ((loop2 <= 0) || (done))
if (mp_timedout || done)
break;
if (res != CURLM_OK) {
@ -254,8 +276,9 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "loop1: %d loop2: %d \n", loop1, loop2);
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
i = 77;
@ -268,7 +291,7 @@ int test(char *URL)
}
}
if ((loop1>0) && (loop2>0)) {
if ((!ml_timedout) && (!mp_timedout)) {
fprintf(stderr, "all done\n");
}

View File

@ -14,6 +14,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
int test(char *URL)
{
int res = 0;
@ -24,8 +29,10 @@ int test(char *URL)
int running;
char done=FALSE;
CURLM *m;
int loop1 = 40;
int loop2 = 20;
struct timeval ml_start;
struct timeval mp_start;
char ml_timedout = FALSE;
char mp_timedout = FALSE;
if (!arg2) {
fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
@ -84,23 +91,38 @@ int test(char *URL)
res = (int)curl_multi_add_handle(m, curl);
while ((--loop1>0) && (loop2>0) && (!done)) {
ml_timedout = FALSE;
ml_start = curlx_tvnow();
while (!done) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
if (curlx_tvdiff(curlx_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
mp_timedout = FALSE;
mp_start = curlx_tvnow();
while (res == CURLM_CALL_MULTI_PERFORM) {
res = (int)curl_multi_perform(m, &running);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
if (running <= 0) {
done = TRUE;
break;
}
}
if ((loop2 <= 0) || (done))
if (mp_timedout || done)
break;
if (res != CURLM_OK) {
@ -128,8 +150,9 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "loop1: %d loop2: %d \n", loop1, loop2);
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;

View File

@ -33,6 +33,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
#define NUM_HANDLES 4
int test(char *URL)
@ -44,8 +49,10 @@ int test(char *URL)
CURLM *m;
int current=0;
int i;
int loop1 = 40;
int loop2 = 20;
struct timeval ml_start;
struct timeval mp_start;
char ml_timedout = FALSE;
char mp_timedout = FALSE;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
@ -67,19 +74,34 @@ int test(char *URL)
res = (int)curl_multi_add_handle(m, curl[current]);
ml_timedout = FALSE;
ml_start = curlx_tvnow();
fprintf(stderr, "Start at URL 0\n");
while ((--loop1>0) && (loop2>0) && (!done)) {
while (!done) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
if (curlx_tvdiff(curlx_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
mp_timedout = FALSE;
mp_start = curlx_tvnow();
while (res == CURLM_CALL_MULTI_PERFORM) {
res = (int)curl_multi_perform(m, &running);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
if (running <= 0) {
#ifdef LIB527
/* NOTE: this code does not remove the handle from the multi handle
@ -115,7 +137,7 @@ int test(char *URL)
break;
}
}
if ((loop2 <= 0) || (done))
if (mp_timedout || done)
break;
if (res != CURLM_OK) {
@ -143,8 +165,9 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "loop1: %d loop2: %d \n", loop1, loop2);
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;

View File

@ -13,6 +13,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
#define NUM_HANDLES 4
int test(char *URL)
@ -23,8 +28,10 @@ int test(char *URL)
char done=FALSE;
CURLM *m;
int i;
int loop1 = 40;
int loop2 = 60;
struct timeval ml_start;
struct timeval mp_start;
char ml_timedout = FALSE;
char mp_timedout = FALSE;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
@ -51,25 +58,40 @@ int test(char *URL)
curl_multi_setopt(m, CURLMOPT_PIPELINING, 1);
ml_timedout = FALSE;
ml_start = curlx_tvnow();
fprintf(stderr, "Start at URL 0\n");
while ((--loop1>0) && (loop2>0) && (!done)) {
while (!done) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 60;
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
if (curlx_tvdiff(curlx_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
mp_timedout = FALSE;
mp_start = curlx_tvnow();
while (res == CURLM_CALL_MULTI_PERFORM) {
res = (int)curl_multi_perform(m, &running);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
if (running <= 0) {
done = TRUE; /* bail out */
break;
}
}
if ((loop2 <= 0) || (done))
if (mp_timedout || done)
break;
if (res != CURLM_OK) {
@ -97,8 +119,9 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "loop1: %d loop2: %d \n", loop1, loop2);
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;

View File

@ -16,6 +16,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
int test(char *URL)
{
int res = 0;
@ -24,8 +29,10 @@ int test(char *URL)
char done=FALSE;
CURLM *m;
int current=0;
int loop1 = 40;
int loop2 = 20;
struct timeval ml_start;
struct timeval mp_start;
char ml_timedout = FALSE;
char mp_timedout = FALSE;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
@ -44,19 +51,34 @@ int test(char *URL)
res = (int)curl_multi_add_handle(m, curl);
ml_timedout = FALSE;
ml_start = curlx_tvnow();
fprintf(stderr, "Start at URL 0\n");
while ((--loop1>0) && (loop2>0) && (!done)) {
while (!done) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
if (curlx_tvdiff(curlx_tvnow(), ml_start) >
MAIN_LOOP_HANG_TIMEOUT) {
ml_timedout = TRUE;
break;
}
mp_timedout = FALSE;
mp_start = curlx_tvnow();
while (res == CURLM_CALL_MULTI_PERFORM) {
res = (int)curl_multi_perform(m, &running);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
if (running <= 0) {
if(!current++) {
fprintf(stderr, "Advancing to URL 1\n");
@ -83,7 +105,7 @@ int test(char *URL)
break;
}
}
if ((loop2 <= 0) || (done))
if (mp_timedout || done)
break;
if (res != CURLM_OK) {
@ -111,8 +133,9 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "loop1: %d loop2: %d \n", loop1, loop2);
if (ml_timedout || mp_timedout) {
if (ml_timedout) fprintf(stderr, "ml_timedout\n");
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;

View File

@ -14,6 +14,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "timeval.h"
#define MAIN_LOOP_HANG_TIMEOUT 45 * 1000
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
static CURLMcode perform(CURLM * multi);
static CURLMcode perform(CURLM * multi)
@ -21,10 +26,19 @@ static CURLMcode perform(CURLM * multi)
int handles, maxfd;
CURLMcode code;
fd_set fdread, fdwrite, fdexcep;
int loop;
struct timeval mp_start;
char mp_timedout = FALSE;
for (loop=40;loop>0;loop--) {
mp_timedout = FALSE;
mp_start = curlx_tvnow();
for (;;) {
code = curl_multi_perform(multi, &handles);
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
mp_timedout = TRUE;
break;
}
if (handles <= 0)
return CURLM_OK;
@ -47,7 +61,8 @@ static CURLMcode perform(CURLM * multi)
return (CURLMcode) ~CURLM_OK;
}
/* We only reach this point if (loop <= 0) */
/* We only reach this point if (mp_timedout) */
fprintf(stderr, "mp_timedout\n");
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
return (CURLMcode) ~CURLM_OK;