Abort test if it seems that it would have run forever. This is just to prevent

test hanging and actually is an indication that there's a condition that is
not being properly handled at some point in the library.

Loop counter limits might need to be further increased on false positives.
This commit is contained in:
Yang Tse 2006-10-19 17:29:25 +00:00
parent 5c3dc49f44
commit ead6ab2ef7
8 changed files with 110 additions and 32 deletions

View File

@ -20,7 +20,8 @@ int test(char *URL)
int running;
int max_fd;
int rc;
int loop=10;
int loop1 = 10;
int loop2 = 20;
curl_global_init(CURL_GLOBAL_ALL);
c = curl_easy_init();
@ -42,12 +43,15 @@ int test(char *URL)
interval.tv_sec = 1;
interval.tv_usec = 0;
int loop2 = 20;
fprintf(stderr, "curl_multi_perform()\n");
do {
res = curl_multi_perform(m, &running);
} while (res == CURLM_CALL_MULTI_PERFORM);
} while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM));
if (loop2 <= 0)
break;
if(!running) {
/* This is where this code is expected to reach */
int numleft;
@ -82,7 +86,12 @@ int test(char *URL)
/* we only allow a certain number of loops to avoid hanging here
forever */
} while(--loop>0);
} while(--loop1>0);
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
ret = 77;
}
}
curl_multi_remove_handle(m, c);

View File

@ -7,6 +7,8 @@ int test(char *URL)
int still_running;
int i = -1;
CURLMsg *msg;
int loop1 = 20;
int loop2 = 40;
multi = curl_multi_init();
@ -14,8 +16,10 @@ int test(char *URL)
curl_easy_setopt(curls, CURLOPT_URL, URL);
curl_multi_add_handle(multi, curls);
while ( CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running) );
while(still_running) {
while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM ==
curl_multi_perform(multi, &still_running)));
while ((loop1>0) && (--loop2>0) && (still_running)) {
struct timeval timeout;
int rc;
fd_set fdread;
@ -34,15 +38,24 @@ int test(char *URL)
break;
case 0:
default:
while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi, &still_running));
loop1 = 20;
while ((--loop1>0) && (CURLM_CALL_MULTI_PERFORM ==
curl_multi_perform(multi, &still_running)));
break;
}
}
msg = curl_multi_info_read(multi, &still_running);
if(msg)
/* this should now contain a result code from the easy handle,
get it */
i = msg->data.result;
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
i = 77;
}
else {
msg = curl_multi_info_read(multi, &still_running);
if(msg)
/* this should now contain a result code from the easy handle,
get it */
i = msg->data.result;
}
curl_multi_cleanup(multi);
curl_easy_cleanup(curls);

View File

@ -175,6 +175,9 @@ int test(char *URL)
int i = 0;
CURLMsg *msg;
int loop1 = 40;
int loop2 = 20;
if(arg2) {
portnum = atoi(arg2);
}
@ -205,15 +208,16 @@ int test(char *URL)
res = curl_multi_add_handle(multi, p.curl);
while(!done) {
while ((--loop1>0) && (loop2>0) && (!done)) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while (res == CURLM_CALL_MULTI_PERFORM) {
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
res = curl_multi_perform(multi, &running);
fprintf(stderr, "running=%d res=%d\n",running,res);
if (running <= 0) {
@ -221,7 +225,7 @@ int test(char *URL)
break;
}
}
if(done)
if ((loop2 <= 0) || (done))
break;
if (res != CURLM_OK) {
@ -249,13 +253,23 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
msg = curl_multi_info_read(multi, &running);
/* this should now contain a result code from the easy handle, get it */
if(msg)
i = msg->data.result;
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
i = 77;
}
else {
msg = curl_multi_info_read(multi, &running);
/* this should now contain a result code from the easy handle, get it */
if(msg)
i = msg->data.result;
}
}
fprintf(stderr, "all done\n");
if ((loop1>0) && (loop2>0)) {
fprintf(stderr, "all done\n");
}
curl_multi_remove_handle(multi, p.curl);
curl_easy_cleanup(p.curl);

View File

@ -24,6 +24,8 @@ int test(char *URL)
int running;
char done=FALSE;
CURLM *m;
int loop1 = 40;
int loop2 = 20;
if (!arg2) {
fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
@ -82,22 +84,23 @@ int test(char *URL)
res = (int)curl_multi_add_handle(m, curl);
while(!done) {
while ((--loop1>0) && (loop2>0) && (!done)) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while (res == CURLM_CALL_MULTI_PERFORM) {
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
res = (int)curl_multi_perform(m, &running);
if (running <= 0) {
done = TRUE;
break;
}
}
if(done)
if ((loop2 <= 0) || (done))
break;
if (res != CURLM_OK) {
@ -125,6 +128,12 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;
}
#ifdef LIB529
/* test 529 */
curl_multi_remove_handle(m, curl);

View File

@ -44,6 +44,8 @@ int test(char *URL)
CURLM *m;
int current=0;
int i;
int loop1 = 40;
int loop2 = 20;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
@ -67,15 +69,16 @@ int test(char *URL)
fprintf(stderr, "Start at URL 0\n");
while(!done) {
while ((--loop1>0) && (loop2>0) && (!done)) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while (res == CURLM_CALL_MULTI_PERFORM) {
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
res = (int)curl_multi_perform(m, &running);
if (running <= 0) {
#ifdef LIB527
@ -112,7 +115,7 @@ int test(char *URL)
break;
}
}
if(done)
if ((loop2 <= 0) || (done))
break;
if (res != CURLM_OK) {
@ -140,6 +143,12 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;
}
#ifndef LIB527
/* get NUM_HANDLES easy handles */
for(i=0; i < NUM_HANDLES; i++) {

View File

@ -23,6 +23,8 @@ int test(char *URL)
char done=FALSE;
CURLM *m;
int i;
int loop1 = 40;
int loop2 = 20;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
@ -51,22 +53,23 @@ int test(char *URL)
fprintf(stderr, "Start at URL 0\n");
while(!done) {
while ((--loop1>0) && (loop2>0) && (!done)) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while (res == CURLM_CALL_MULTI_PERFORM) {
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
res = (int)curl_multi_perform(m, &running);
if (running <= 0) {
done = TRUE; /* bail out */
break;
}
}
if(done)
if ((loop2 <= 0) || (done))
break;
if (res != CURLM_OK) {
@ -94,6 +97,12 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;
}
/* get NUM_HANDLES easy handles */
for(i=0; i < NUM_HANDLES; i++) {
curl_multi_remove_handle(m, curl[i]);

View File

@ -24,6 +24,8 @@ int test(char *URL)
char done=FALSE;
CURLM *m;
int current=0;
int loop1 = 40;
int loop2 = 20;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
@ -44,15 +46,16 @@ int test(char *URL)
fprintf(stderr, "Start at URL 0\n");
while(!done) {
while ((--loop1>0) && (loop2>0) && (!done)) {
fd_set rd, wr, exc;
int max_fd;
struct timeval interval;
interval.tv_sec = 1;
interval.tv_usec = 0;
loop2 = 20;
while (res == CURLM_CALL_MULTI_PERFORM) {
while ((--loop2>0) && (res == CURLM_CALL_MULTI_PERFORM)) {
res = (int)curl_multi_perform(m, &running);
if (running <= 0) {
if(!current++) {
@ -80,7 +83,7 @@ int test(char *URL)
break;
}
}
if(done)
if ((loop2 <= 0) || (done))
break;
if (res != CURLM_OK) {
@ -108,6 +111,12 @@ int test(char *URL)
res = CURLM_CALL_MULTI_PERFORM;
}
if ((loop1 <= 0) || (loop2 <= 0)) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
res = 77;
}
curl_easy_cleanup(curl);
curl_multi_cleanup(m);

View File

@ -21,8 +21,9 @@ static CURLMcode perform(CURLM * multi)
int handles, maxfd;
CURLMcode code;
fd_set fdread, fdwrite, fdexcep;
int loop;
for (;;) {
for (loop=40;loop>0;loop--) {
code = curl_multi_perform(multi, &handles);
if (handles <= 0)
return CURLM_OK;
@ -45,6 +46,11 @@ static CURLMcode perform(CURLM * multi)
if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, 0) == -1)
return (CURLMcode) ~CURLM_OK;
}
if (loop <= 0) {
fprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
return (CURLMcode) ~CURLM_OK;
}
}
int test(char *URL)