]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: test-http-client-errors: Terminate the test if it is hanging for some reason.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 28 Dec 2017 15:33:49 +0000 (16:33 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 6 Feb 2019 08:08:17 +0000 (10:08 +0200)
src/lib-http/test-http-client-errors.c

index b5fb7e0d73f88c03d17436ea9fe090b457d87a51..e2c6badcfd8e454451033db189f4f1f4901d7c93 100644 (file)
@@ -19,6 +19,8 @@
 #include <signal.h>
 #include <unistd.h>
 
+#define CLIENT_PROGRESS_TIMEOUT     10
+
 /*
  * Types
  */
@@ -59,6 +61,7 @@ static unsigned int server_index;
 static void (*test_server_input)(struct server_connection *conn);
 
 /* client */
+static struct timeout *to_client_progress = NULL;
 static struct http_client *http_client = NULL;
 
 /*
@@ -2979,11 +2982,44 @@ test_client_defaults(struct http_client_settings *http_set)
        http_set->debug = debug;
 }
 
+static void
+test_client_progress_timeout(void *context ATTR_UNUSED)
+{
+       /* Terminate test due to lack of progress */
+       test_assert(FALSE);
+       timeout_remove(&to_client_progress);
+       io_loop_stop(current_ioloop);
+}
+
+static bool
+test_client_init(test_client_init_t client_test,
+                const struct http_client_settings *client_set)
+{
+       i_assert(client_test != NULL);
+       if (!client_test(client_set))
+               return FALSE;
+
+       to_client_progress = timeout_add(CLIENT_PROGRESS_TIMEOUT*1000,
+               test_client_progress_timeout, NULL);
+
+       return TRUE;
+}
+
 static void test_client_deinit(void)
 {
+       timeout_remove(&to_client_progress);
+
        if (http_client != NULL)
                http_client_deinit(&http_client);
-       http_client = NULL;
+}
+
+static void
+test_client_run(test_client_init_t client_test,
+               const struct http_client_settings *client_set)
+{
+       if (test_client_init(client_test, client_set))
+               io_loop_run(ioloop);
+       test_client_deinit();
 }
 
 /*
@@ -3210,9 +3246,7 @@ static void test_run_client_server(
        usleep(100000); /* wait a little for server setup */
 
        ioloop = io_loop_create();
-       if (client_test(client_set))
-               io_loop_run(ioloop);
-       test_client_deinit();
+       test_client_run(client_test, client_set);
        io_loop_destroy(&ioloop);
 
        test_servers_kill_all();