]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: test-smtp-client-errors - Split off test_run_server/dns/client() from test_...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 8 Apr 2020 20:37:59 +0000 (22:37 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 25 May 2020 15:29:02 +0000 (17:29 +0200)
src/lib-smtp/test-smtp-client-errors.c

index 6cfa5ef4f11a52cd86cd639eba3e8609736b49d4..c19f2a5f34c5478cc811658f0a57437ecf28f146 100644 (file)
@@ -3862,6 +3862,52 @@ static void test_servers_kill_forced(void)
        }
 }
 
+static void test_run_server(unsigned int index, test_server_init_t server_test)
+{
+       i_set_failure_prefix("SERVER[%u]: ", index + 1);
+
+       if (debug)
+               i_debug("PID=%s", my_pid);
+
+       ioloop = io_loop_create();
+       server_test(index);
+       io_loop_destroy(&ioloop);
+
+       i_close_fd(&fd_listen);
+       i_free(bind_ports);
+}
+
+static void test_run_dns(test_dns_init_t dns_test)
+{
+       i_set_failure_prefix("DNS: ");
+
+       if (debug)
+               i_debug("PID=%s", my_pid);
+
+       ioloop = io_loop_create();
+       dns_test();
+       io_loop_destroy(&ioloop);
+
+       i_close_fd(&fd_listen);
+       i_free(bind_ports);
+}
+
+static void
+test_run_client(const struct smtp_client_settings *client_set,
+               test_client_init_t client_test)
+{
+       i_set_failure_prefix("CLIENT: ");
+
+       if (debug)
+               i_debug("PID=%s", my_pid);
+
+       i_sleep_msecs(100); /* wait a little for server setup */
+
+       ioloop = io_loop_create();
+       test_client_run(client_test, client_set);
+       io_loop_destroy(&ioloop);
+}
+
 static void
 test_run_client_server(const struct smtp_client_settings *client_set,
                       test_client_init_t client_test,
@@ -3898,15 +3944,10 @@ test_run_client_server(const struct smtp_client_settings *client_set,
                                server_pids_count = 0;
                                hostpid_init();
                                lib_signals_deinit();
+
                                /* child: server */
-                               i_set_failure_prefix("SERVER[%u]: ", i + 1);
-                               if (debug)
-                                       i_debug("PID=%s", my_pid);
-                               ioloop = io_loop_create();
-                               server_test(i);
-                               io_loop_destroy(&ioloop);
-                               i_close_fd(&fd_listen);
-                               i_free(bind_ports);
+                               test_run_server(i, server_test);
+
                                i_free(server_pids);
                                /* wait for it to be killed; this way, valgrind
                                   will not object to this process going away
@@ -3934,14 +3975,10 @@ test_run_client_server(const struct smtp_client_settings *client_set,
                        dns_pid = (pid_t)-1;
                        hostpid_init();
                        lib_signals_deinit();
+
                        /* child: server */
-                       i_set_failure_prefix("DNS: ");
-                       if (debug)
-                               i_debug("PID=%s", my_pid);
-                       ioloop = io_loop_create();
-                       dns_test();
-                       io_loop_destroy(&ioloop);
-                       i_close_fd(&fd_listen);
+                       test_run_dns(dns_test);
+
                        /* wait for it to be killed; this way, valgrind will not
                           object to this process going away inelegantly. */
                        i_sleep_intr_secs(60);
@@ -3953,15 +3990,7 @@ test_run_client_server(const struct smtp_client_settings *client_set,
        lib_signals_ioloop_attach();
 
        /* parent: client */
-       i_set_failure_prefix("CLIENT: ");
-       if (debug)
-               i_debug("PID=%s", my_pid);
-
-       i_sleep_msecs(100); /* wait a little for server setup */
-
-       ioloop = io_loop_create();
-       test_client_run(client_test, client_set);
-       io_loop_destroy(&ioloop);
+       test_run_client(client_set, client_test);
 
        i_unset_failure_prefix();
        test_servers_kill_forced();