libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit c9d390f42df8f8311cac0a254c7819d93e3a7334
parent 8395ad601ed8b39c0d0c33f40c7bacff29ca03f9
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun, 29 Aug 2021 18:01:32 +0300

test_timeout: improved: added more error detection and reporting

Diffstat:
Msrc/testcurl/test_timeout.c | 57+++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 45 insertions(+), 12 deletions(-)

diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c @@ -41,9 +41,9 @@ static int oneone; -static int withTimeout = 1; +static int withTimeout = 0; -static int withoutTimeout = 1; +static int withoutTimeout = 0; struct CBC { @@ -67,21 +67,40 @@ termination_cb (void *cls, case MHD_REQUEST_TERMINATED_COMPLETED_OK: if (test == &withoutTimeout) { - withoutTimeout = 0; + withoutTimeout = 1; + } + else + { + fprintf (stderr, "Connection completed without errors while " + "timeout is expected.\n"); } break; case MHD_REQUEST_TERMINATED_WITH_ERROR: + fprintf (stderr, "Connection terminated with error.\n"); + exit (4); + break; case MHD_REQUEST_TERMINATED_READ_ERROR: + fprintf (stderr, "Connection terminated with read error.\n"); + exit (4); break; case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED: if (test == &withTimeout) { - withTimeout = 0; + withTimeout = 1; + } + else + { + fprintf (stderr, "Connection terminated with timeout while expected " + "to be successfully completed.\n"); } break; case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: + fprintf (stderr, "Connection terminated by daemon shutdown.\n"); + exit (4); break; case MHD_REQUEST_TERMINATED_CLIENT_ABORT: + fprintf (stderr, "Connection terminated by client.\n"); + exit (4); break; } } @@ -193,7 +212,7 @@ testWithoutTimeout () NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_CONNECTION_TIMEOUT, 2, MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, - &withTimeout, + &withoutTimeout, MHD_OPTION_END); if (d == NULL) return 1; @@ -227,6 +246,7 @@ testWithoutTimeout () * setting NOSIGNAL results in really weird * crashes on my system! */ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); + withoutTimeout = 0; if (CURLE_OK != (errornum = curl_easy_perform (c))) { fprintf (stderr, "curl_easy_perform failed: '%s'\n", @@ -237,6 +257,11 @@ testWithoutTimeout () } curl_easy_cleanup (c); MHD_stop_daemon (d); + if (0 == withoutTimeout) + { + fprintf (stderr, "Request wasn't processed successfully.\n"); + return 2; + } if (cbc.pos != strlen ("/hello_world")) return 4; if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) @@ -273,7 +298,7 @@ testWithTimeout () NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_CONNECTION_TIMEOUT, 2, MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, - &withoutTimeout, + &withTimeout, MHD_OPTION_END); if (d == NULL) return 16; @@ -307,13 +332,24 @@ testWithTimeout () * setting NOSIGNAL results in really weird * crashes on my system! */ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); + withTimeout = 0; if (CURLE_OK != (errornum = curl_easy_perform (c))) { curl_easy_cleanup (c); MHD_stop_daemon (d); if (errornum == CURLE_GOT_NOTHING) - /* mhd had the timeout */ - return 0; + { + if (0 != withTimeout) + { + /* mhd had the timeout */ + return 0; + } + else + { + fprintf (stderr, "Timeout wasn't detected.\n"); + return 8; + } + } else /* curl had the timeout first */ return 32; @@ -342,8 +378,5 @@ main (int argc, char *const *argv) "Error during test execution (code: %u)\n", errorCount); curl_global_cleanup (); - if ((withTimeout == 0) && (withoutTimeout == 0)) - return 0; - else - return errorCount; /* 0 == pass */ + return errorCount; /* 0 == pass */ }