aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest/lib507.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2006-10-20 15:39:54 +0000
committerYang Tse <yangsita@gmail.com>2006-10-20 15:39:54 +0000
commitb9ccecf86e96e173ffe3b4026c84e61e53d3ff68 (patch)
tree3ba2198ddda7a2880264fd4cb815969676c20cda /tests/libtest/lib507.c
parentbd5d21aaf23cd20b74ad13e9d8ca16e81a4aea48 (diff)
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.
Diffstat (limited to 'tests/libtest/lib507.c')
-rw-r--r--tests/libtest/lib507.c56
1 files changed, 46 insertions, 10 deletions
diff --git a/tests/libtest/lib507.c b/tests/libtest/lib507.c
index 9a98da728..b06d65fe2 100644
--- a/tests/libtest/lib507.c
+++ b/tests/libtest/lib507.c
@@ -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();
+
+ 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 ((loop1>0) && (--loop2>0) && (still_running)) {
+ 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;