]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: server: Improved test-http-payload to test partial reading of request payload.
authorStephan Bosch <stephan@rename-it.nl>
Thu, 3 Mar 2016 21:29:44 +0000 (22:29 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 16 Mar 2016 00:09:16 +0000 (11:09 +1100)
src/lib-http/test-http-payload.c

index 93a831e929e3932b5fe7f48b2c08284b287ad632..da140b04c942a731a51bd16b44b7c29290428c07 100644 (file)
 #include <unistd.h>
 #include <dirent.h>
 
-static bool blocking = FALSE;
 static bool debug = FALSE;
+
+static bool blocking = FALSE;
 static bool request_100_continue = FALSE;
+static size_t read_partial = 1024;
 static unsigned int test_max_pending = 200;
 
 static struct ip_addr bind_ip;
@@ -342,6 +344,14 @@ client_handle_echo_request(struct client_request *creq,
 
                payload_input =
                        http_server_request_get_payload_input(req, TRUE);
+
+               if (read_partial > 0) {
+                       struct istream *partial =
+                               i_stream_create_limit(payload_input, read_partial);
+                       i_stream_unref(&payload_input);
+                       payload_input = partial;
+               }
+
                while ((ret=o_stream_send_istream
                        (payload_output, payload_input)) > 0);
                if (ret < 0) {
@@ -381,6 +391,14 @@ client_handle_echo_request(struct client_request *creq,
                creq->payload_output = payload_output;
                creq->payload_input =
                        http_server_request_get_payload_input(req, FALSE);
+
+               if (read_partial > 0) {
+                       struct istream *partial =
+                               i_stream_create_limit(creq->payload_input, read_partial);
+                       i_stream_unref(&creq->payload_input);
+                       creq->payload_input = partial;
+               }
+
                creq->io = io_add_istream(creq->payload_input,
                                 client_request_read_echo_more, creq);
                client_request_read_echo_more(creq);
@@ -938,6 +956,13 @@ test_client_echo_response(const struct http_response *resp,
                        "failed to open %s", path);
        }
 
+       if (read_partial > 0) {
+               struct istream *partial =
+                       i_stream_create_limit(fstream, read_partial);
+               i_stream_unref(&fstream);
+               fstream = partial;
+       }
+
        if (resp->payload == NULL) {
                // FIXME: check file is empty
                if (debug) {
@@ -978,8 +1003,13 @@ static void test_client_echo_continue(void)
 
        if (debug) {
                i_debug("test client: echo: "
-                       "received until [%u]",
-                       client_files_first-1);
+                       "received until [%u/%u]", client_files_first-1, count);
+       }
+
+       if (debug && client_files_first < count) {
+               const char *path = paths[client_files_first];
+               i_debug("test client: echo: "
+                       "next blocking: %s", (path == NULL ? "none" : path));
        }
 
        if (client_files_first >= count) {
@@ -1128,6 +1158,8 @@ static void test_run_sequential(
        test_run_client_server
                (&http_client_set, &http_server_set, client_init);
        test_files_deinit();
+
+       test_out("sequential", TRUE);
 }
 
 static void test_run_pipeline(
@@ -1148,7 +1180,7 @@ static void test_run_pipeline(
        memset(&http_client_set, 0, sizeof(http_client_set));
        http_client_set.max_idle_time_msecs = 5*1000;
        http_client_set.max_parallel_connections = 1;
-       http_client_set.max_pipelined_requests = 4;
+       http_client_set.max_pipelined_requests = 8;
        http_client_set.max_redirects = 0;
        http_client_set.max_attempts = 1;
        http_client_set.debug = debug;
@@ -1157,6 +1189,8 @@ static void test_run_pipeline(
        test_run_client_server
                (&http_client_set, &http_server_set, client_init);
        test_files_deinit();
+
+       test_out("pipeline", TRUE);
 }
 
 static void test_run_parallel(
@@ -1177,7 +1211,7 @@ static void test_run_parallel(
        memset(&http_client_set, 0, sizeof(http_client_set));
        http_client_set.max_idle_time_msecs = 5*1000;
        http_client_set.max_parallel_connections = 40;
-       http_client_set.max_pipelined_requests = 4;
+       http_client_set.max_pipelined_requests = 8;
        http_client_set.max_redirects = 0;
        http_client_set.max_attempts = 1;
        http_client_set.debug = debug;
@@ -1186,12 +1220,16 @@ static void test_run_parallel(
        test_run_client_server
                (&http_client_set, &http_server_set, client_init);
        test_files_deinit();
+
+       test_out("parallel", TRUE);
 }
 
 static void test_download_server_nonblocking(void)
 {
        test_begin("http payload download (server non-blocking)");
        blocking = FALSE;
+       request_100_continue = FALSE;
+       read_partial = 0;
        test_run_sequential(test_client_download);
        test_run_pipeline(test_client_download);
        test_run_parallel(test_client_download);
@@ -1202,6 +1240,8 @@ static void test_download_server_blocking(void)
 {
        test_begin("http payload download (server blocking)");
        blocking = TRUE;
+       request_100_continue = FALSE;
+       read_partial = 0;
        test_run_sequential(test_client_download);
        test_run_pipeline(test_client_download);
        test_run_parallel(test_client_download);
@@ -1210,8 +1250,10 @@ static void test_download_server_blocking(void)
 
 static void test_echo_server_nonblocking(void)
 {
-       test_begin("http payload echo (server non-blocking");
+       test_begin("http payload echo (server non-blocking)");
        blocking = FALSE;
+       request_100_continue = FALSE;
+       read_partial = 0;
        test_run_sequential(test_client_echo);
        test_run_pipeline(test_client_echo);
        test_run_parallel(test_client_echo);
@@ -1222,6 +1264,8 @@ static void test_echo_server_blocking(void)
 {
        test_begin("http payload echo (server blocking)");
        blocking = TRUE;
+       request_100_continue = FALSE;
+       read_partial = 0;
        test_run_sequential(test_client_echo);
        test_run_pipeline(test_client_echo);
        test_run_parallel(test_client_echo);
@@ -1231,8 +1275,9 @@ static void test_echo_server_blocking(void)
 static void test_echo_server_nonblocking_sync(void)
 {
        test_begin("http payload echo (server non-blocking; 100-continue)");
-       request_100_continue = TRUE;
        blocking = FALSE;
+       request_100_continue = TRUE;
+       read_partial = 0;
        test_run_sequential(test_client_echo);
        test_run_pipeline(test_client_echo);
        test_run_parallel(test_client_echo);
@@ -1242,14 +1287,51 @@ static void test_echo_server_nonblocking_sync(void)
 static void test_echo_server_blocking_sync(void)
 {
        test_begin("http payload echo (server blocking; 100-continue)");
-       request_100_continue = TRUE;
        blocking = TRUE;
+       request_100_continue = TRUE;
+       read_partial = 0;
   test_run_sequential(test_client_echo);
        test_run_pipeline(test_client_echo);
        test_run_parallel(test_client_echo);
        test_end();
 }
 
+static void test_echo_server_nonblocking_partial(void)
+{
+       test_begin("http payload echo (server non-blocking; partial short)");
+       blocking = FALSE;
+       request_100_continue = FALSE;
+       read_partial = 1024;
+       test_run_sequential(test_client_echo);
+       test_run_pipeline(test_client_echo);
+       test_run_parallel(test_client_echo);
+       test_end();
+       test_begin("http payload echo (server non-blocking; partial long)");
+       read_partial = IO_BLOCK_SIZE + 1024;
+       test_run_sequential(test_client_echo);
+       test_run_pipeline(test_client_echo);
+       test_run_parallel(test_client_echo);
+       test_end();
+}
+
+static void test_echo_server_blocking_partial(void)
+{
+       test_begin("http payload echo (server blocking; partial short)");
+       blocking = TRUE;
+       request_100_continue = FALSE;
+       read_partial = 1024;
+       test_run_sequential(test_client_echo);
+       test_run_pipeline(test_client_echo);
+       test_run_parallel(test_client_echo);
+       test_end();
+       test_begin("http payload echo (server blocking; partial long)");
+       read_partial = IO_BLOCK_SIZE + 1024;
+       test_run_sequential(test_client_echo);
+       test_run_pipeline(test_client_echo);
+       test_run_parallel(test_client_echo);
+       test_end();
+}
+
 static void (*test_functions[])(void) = {
        test_download_server_nonblocking,
        test_download_server_blocking,
@@ -1257,6 +1339,8 @@ static void (*test_functions[])(void) = {
        test_echo_server_blocking,
        test_echo_server_nonblocking_sync,
        test_echo_server_blocking_sync,
+       test_echo_server_nonblocking_partial,
+       test_echo_server_blocking_partial,
        NULL
 };