]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: test-http-client: Run several clients simultaneously.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 27 Sep 2017 17:21:40 +0000 (19:21 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 7 Dec 2017 16:40:45 +0000 (18:40 +0200)
src/lib-http/test-http-client.c

index d19791ffd6bb17c0107939289b5b7d257f285534..2d3fdca8190159223118668ff3cfc4d24955e3bc 100644 (file)
@@ -19,6 +19,8 @@ struct http_test_request {
        bool write_output;
 };
 
+static struct ioloop *ioloop;
+
 static void payload_input(struct http_test_request *req)
 {
        const unsigned char *data;
@@ -53,6 +55,8 @@ static void
 got_request_response(const struct http_response *response,
                     struct http_test_request *req)
 {
+       io_loop_stop(ioloop);
+
        if (response->status / 100 != 2) {
                i_error("HTTP Request failed: %s", response->reason);
                i_free(req);
@@ -340,10 +344,10 @@ int main(int argc, char *argv[])
        struct dns_client *dns_client;
        struct dns_lookup_settings dns_set;
        struct http_client_settings http_set;
-       struct http_client *http_client;
+       struct http_client_context *http_cctx;
+       struct http_client *http_client1, *http_client2, *http_client3, *http_client4;
        struct ssl_iostream_settings ssl_set;
        const char *error;
-       struct ioloop *ioloop;
 
        lib_init();
 #ifdef HAVE_OPENSSL
@@ -382,24 +386,62 @@ int main(int argc, char *argv[])
        http_set.debug = TRUE;
        http_set.rawlog_dir = "/tmp/http-test";
 
-       http_client = http_client_init(&http_set);
+       http_cctx = http_client_context_create(&http_set);
+
+       http_client1 = http_client_init_shared(http_cctx, NULL);
+       http_client2 = http_client_init_shared(http_cctx, NULL);
+       http_client3 = http_client_init_shared(http_cctx, NULL);
+       http_client4 = http_client_init_shared(http_cctx, NULL);
 
        switch (argc) {
        case 1:
-               run_tests(http_client);
+               run_tests(http_client1);
+               run_tests(http_client2);
+               run_tests(http_client3);
+               run_tests(http_client4);
                break;
        case 2:
-               run_http_get(http_client, argv[1]);
+               run_http_get(http_client1, argv[1]);
+               run_http_get(http_client2, argv[1]);
+               run_http_get(http_client3, argv[1]);
+               run_http_get(http_client4, argv[1]);
                break;
        case 3:
-               run_http_post(http_client, argv[1], argv[2]);
+               run_http_post(http_client1, argv[1], argv[2]);
+               run_http_post(http_client2, argv[1], argv[2]);
+               run_http_post(http_client3, argv[1], argv[2]);
+               run_http_post(http_client4, argv[1], argv[2]);
                break;
        default:
                i_fatal("Too many parameters");
        }
 
-       http_client_wait(http_client);
-       http_client_deinit(&http_client);
+       for (;;) {
+               bool pending = FALSE;
+
+               if (http_client_get_pending_request_count(http_client1) > 0) {
+                       i_debug("Requests still pending in client 1");
+                       pending = TRUE;
+               } else if (http_client_get_pending_request_count(http_client2) > 0) {
+                       i_debug("Requests still pending in client 2");
+                       pending = TRUE;
+               } else if (http_client_get_pending_request_count(http_client3) > 0) {
+                       i_debug("Requests still pending in client 3");
+                       pending = TRUE;
+               } else if (http_client_get_pending_request_count(http_client4) > 0) {
+                       i_debug("Requests still pending in client 4");
+                       pending = TRUE;
+               }
+               if (!pending)
+                       break;
+               io_loop_run(ioloop);
+       }
+       http_client_deinit(&http_client1);
+       http_client_deinit(&http_client2);
+       http_client_deinit(&http_client3);
+       http_client_deinit(&http_client4);
+
+       http_client_context_unref(&http_cctx);
 
        dns_client_deinit(&dns_client);