aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Dudka <kdudka@redhat.com>2011-08-26 11:10:58 +0200
committerKamil Dudka <kdudka@redhat.com>2011-08-29 15:14:39 +0200
commit3445fa2e3f28b359a3acd2a884f4e119b11e0a57 (patch)
treed8c71990e6fa7bf22736b35bf0ae51355c0ab896
parent5a45dc4a29b7b65406b8e3d1a78bed99478a9a3a (diff)
tests: break busy loops in tests 502, 555, and 573
-rw-r--r--tests/libtest/lib502.c23
-rw-r--r--tests/libtest/lib555.c23
-rw-r--r--tests/libtest/lib573.c23
3 files changed, 63 insertions, 6 deletions
diff --git a/tests/libtest/lib502.c b/tests/libtest/lib502.c
index 9ade12afb..9040b2be3 100644
--- a/tests/libtest/lib502.c
+++ b/tests/libtest/lib502.c
@@ -73,6 +73,10 @@ int test(char *URL)
mp_start = tutil_tvnow();
while (running) {
+ static struct timeval timeout = /* 100 ms */ { 0, 100000L };
+ fd_set fdread, fdwrite, fdexcep;
+ int maxfd = -1;
+
res = (int)curl_multi_perform(m, &running);
if (tutil_tvdiff(tutil_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
@@ -83,11 +87,26 @@ int test(char *URL)
fprintf(stderr, "nothing left running.\n");
break;
}
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+ curl_multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* In a real-world program you OF COURSE check the return code of the
+ function calls. On success, the value of maxfd is guaranteed to be
+ greater or equal than -1. We call select(maxfd + 1, ...), specially in
+ case of (maxfd == -1), we call select(0, ...), which is basically equal
+ to sleep. */
+
+ if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1) {
+ res = ~CURLM_OK;
+ break;
+ }
}
if (mp_timedout) {
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
+ fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems "
"that it would have run forever.\n");
res = TEST_ERR_RUNS_FOREVER;
}
diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c
index c67501521..1e73a5a2e 100644
--- a/tests/libtest/lib555.c
+++ b/tests/libtest/lib555.c
@@ -135,6 +135,10 @@ int test(char *URL)
mp_start = tutil_tvnow();
while (running) {
+ static struct timeval timeout = /* 100 ms */ { 0, 100000L };
+ fd_set fdread, fdwrite, fdexcep;
+ int maxfd = -1;
+
res = (int)curl_multi_perform(m, &running);
if (tutil_tvdiff(tutil_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
@@ -148,11 +152,26 @@ int test(char *URL)
fprintf(stderr, "nothing left running.\n");
break;
}
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+ curl_multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* In a real-world program you OF COURSE check the return code of the
+ function calls. On success, the value of maxfd is guaranteed to be
+ greater or equal than -1. We call select(maxfd + 1, ...), specially in
+ case of (maxfd == -1), we call select(0, ...), which is basically equal
+ to sleep. */
+
+ if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1) {
+ res = ~CURLM_OK;
+ break;
+ }
}
if (mp_timedout) {
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
+ fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems "
"that it would have run forever.\n");
res = TEST_ERR_RUNS_FOREVER;
}
diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c
index 466185844..b5fafe16e 100644
--- a/tests/libtest/lib573.c
+++ b/tests/libtest/lib573.c
@@ -76,6 +76,10 @@ int test(char *URL)
mp_start = tutil_tvnow();
while (running) {
+ static struct timeval timeout = /* 100 ms */ { 0, 100000L };
+ fd_set fdread, fdwrite, fdexcep;
+ int maxfd = -1;
+
res = (int)curl_multi_perform(m, &running);
if (tutil_tvdiff(tutil_tvnow(), mp_start) >
MULTI_PERFORM_HANG_TIMEOUT) {
@@ -86,11 +90,26 @@ int test(char *URL)
fprintf(stderr, "nothing left running.\n");
break;
}
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+ curl_multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* In a real-world program you OF COURSE check the return code of the
+ function calls. On success, the value of maxfd is guaranteed to be
+ greater or equal than -1. We call select(maxfd + 1, ...), specially in
+ case of (maxfd == -1), we call select(0, ...), which is basically equal
+ to sleep. */
+
+ if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1) {
+ res = ~CURLM_OK;
+ break;
+ }
}
if (mp_timedout) {
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
+ fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems "
"that it would have run forever.\n");
res = TEST_ERR_RUNS_FOREVER;
}