aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_timeout.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_timeout.c')
-rw-r--r--src/testcurl/test_timeout.c57
1 files changed, 45 insertions, 12 deletions
diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c
index 73a4e60f..957fb2cc 100644
--- a/src/testcurl/test_timeout.c
+++ b/src/testcurl/test_timeout.c
@@ -41,9 +41,9 @@
41 41
42static int oneone; 42static int oneone;
43 43
44static int withTimeout = 1; 44static int withTimeout = 0;
45 45
46static int withoutTimeout = 1; 46static int withoutTimeout = 0;
47 47
48struct CBC 48struct CBC
49{ 49{
@@ -67,21 +67,40 @@ termination_cb (void *cls,
67 case MHD_REQUEST_TERMINATED_COMPLETED_OK: 67 case MHD_REQUEST_TERMINATED_COMPLETED_OK:
68 if (test == &withoutTimeout) 68 if (test == &withoutTimeout)
69 { 69 {
70 withoutTimeout = 0; 70 withoutTimeout = 1;
71 }
72 else
73 {
74 fprintf (stderr, "Connection completed without errors while "
75 "timeout is expected.\n");
71 } 76 }
72 break; 77 break;
73 case MHD_REQUEST_TERMINATED_WITH_ERROR: 78 case MHD_REQUEST_TERMINATED_WITH_ERROR:
79 fprintf (stderr, "Connection terminated with error.\n");
80 exit (4);
81 break;
74 case MHD_REQUEST_TERMINATED_READ_ERROR: 82 case MHD_REQUEST_TERMINATED_READ_ERROR:
83 fprintf (stderr, "Connection terminated with read error.\n");
84 exit (4);
75 break; 85 break;
76 case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED: 86 case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED:
77 if (test == &withTimeout) 87 if (test == &withTimeout)
78 { 88 {
79 withTimeout = 0; 89 withTimeout = 1;
90 }
91 else
92 {
93 fprintf (stderr, "Connection terminated with timeout while expected "
94 "to be successfully completed.\n");
80 } 95 }
81 break; 96 break;
82 case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: 97 case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN:
98 fprintf (stderr, "Connection terminated by daemon shutdown.\n");
99 exit (4);
83 break; 100 break;
84 case MHD_REQUEST_TERMINATED_CLIENT_ABORT: 101 case MHD_REQUEST_TERMINATED_CLIENT_ABORT:
102 fprintf (stderr, "Connection terminated by client.\n");
103 exit (4);
85 break; 104 break;
86 } 105 }
87} 106}
@@ -193,7 +212,7 @@ testWithoutTimeout ()
193 NULL, NULL, &ahc_echo, &done_flag, 212 NULL, NULL, &ahc_echo, &done_flag,
194 MHD_OPTION_CONNECTION_TIMEOUT, 2, 213 MHD_OPTION_CONNECTION_TIMEOUT, 2,
195 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, 214 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb,
196 &withTimeout, 215 &withoutTimeout,
197 MHD_OPTION_END); 216 MHD_OPTION_END);
198 if (d == NULL) 217 if (d == NULL)
199 return 1; 218 return 1;
@@ -227,6 +246,7 @@ testWithoutTimeout ()
227 * setting NOSIGNAL results in really weird 246 * setting NOSIGNAL results in really weird
228 * crashes on my system! */ 247 * crashes on my system! */
229 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 248 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
249 withoutTimeout = 0;
230 if (CURLE_OK != (errornum = curl_easy_perform (c))) 250 if (CURLE_OK != (errornum = curl_easy_perform (c)))
231 { 251 {
232 fprintf (stderr, "curl_easy_perform failed: '%s'\n", 252 fprintf (stderr, "curl_easy_perform failed: '%s'\n",
@@ -237,6 +257,11 @@ testWithoutTimeout ()
237 } 257 }
238 curl_easy_cleanup (c); 258 curl_easy_cleanup (c);
239 MHD_stop_daemon (d); 259 MHD_stop_daemon (d);
260 if (0 == withoutTimeout)
261 {
262 fprintf (stderr, "Request wasn't processed successfully.\n");
263 return 2;
264 }
240 if (cbc.pos != strlen ("/hello_world")) 265 if (cbc.pos != strlen ("/hello_world"))
241 return 4; 266 return 4;
242 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 267 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
@@ -273,7 +298,7 @@ testWithTimeout ()
273 NULL, NULL, &ahc_echo, &done_flag, 298 NULL, NULL, &ahc_echo, &done_flag,
274 MHD_OPTION_CONNECTION_TIMEOUT, 2, 299 MHD_OPTION_CONNECTION_TIMEOUT, 2,
275 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, 300 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb,
276 &withoutTimeout, 301 &withTimeout,
277 MHD_OPTION_END); 302 MHD_OPTION_END);
278 if (d == NULL) 303 if (d == NULL)
279 return 16; 304 return 16;
@@ -307,13 +332,24 @@ testWithTimeout ()
307 * setting NOSIGNAL results in really weird 332 * setting NOSIGNAL results in really weird
308 * crashes on my system! */ 333 * crashes on my system! */
309 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 334 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
335 withTimeout = 0;
310 if (CURLE_OK != (errornum = curl_easy_perform (c))) 336 if (CURLE_OK != (errornum = curl_easy_perform (c)))
311 { 337 {
312 curl_easy_cleanup (c); 338 curl_easy_cleanup (c);
313 MHD_stop_daemon (d); 339 MHD_stop_daemon (d);
314 if (errornum == CURLE_GOT_NOTHING) 340 if (errornum == CURLE_GOT_NOTHING)
315 /* mhd had the timeout */ 341 {
316 return 0; 342 if (0 != withTimeout)
343 {
344 /* mhd had the timeout */
345 return 0;
346 }
347 else
348 {
349 fprintf (stderr, "Timeout wasn't detected.\n");
350 return 8;
351 }
352 }
317 else 353 else
318 /* curl had the timeout first */ 354 /* curl had the timeout first */
319 return 32; 355 return 32;
@@ -342,8 +378,5 @@ main (int argc, char *const *argv)
342 "Error during test execution (code: %u)\n", 378 "Error during test execution (code: %u)\n",
343 errorCount); 379 errorCount);
344 curl_global_cleanup (); 380 curl_global_cleanup ();
345 if ((withTimeout == 0) && (withoutTimeout == 0)) 381 return errorCount; /* 0 == pass */
346 return 0;
347 else
348 return errorCount; /* 0 == pass */
349} 382}