From b9ccecf86e96e173ffe3b4026c84e61e53d3ff68 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 20 Oct 2006 15:39:54 +0000 Subject: 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. --- tests/libtest/lib509.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'tests/libtest/lib509.c') diff --git a/tests/libtest/lib509.c b/tests/libtest/lib509.c index 5d385c966..77d5e1c6b 100644 --- a/tests/libtest/lib509.c +++ b/tests/libtest/lib509.c @@ -18,6 +18,11 @@ #include #include +#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"); } -- cgit v1.2.3