summaryrefslogtreecommitdiff
path: root/tests/libtest/lib525.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/lib525.c
parentbd5d21aaf23cd20b74ad13e9d8ca16e81a4aea48 (diff)
downloadgnurl-b9ccecf86e96e173ffe3b4026c84e61e53d3ff68.tar.gz
gnurl-b9ccecf86e96e173ffe3b4026c84e61e53d3ff68.tar.bz2
gnurl-b9ccecf86e96e173ffe3b4026c84e61e53d3ff68.zip
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/lib525.c')
-rw-r--r--tests/libtest/lib525.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/tests/libtest/lib525.c b/tests/libtest/lib525.c
index 35c504b97..7ed10dcb7 100644
--- a/tests/libtest/lib525.c
+++ b/tests/libtest/lib525.c
@@ -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;