From: Stephan Bosch Date: Wed, 8 Apr 2020 20:37:59 +0000 (+0200) Subject: lib-smtp: test-smtp-client-errors - Split off test_run_server/dns/client() from test_... X-Git-Tag: 2.3.13~632 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc19d780fd6d1164ac566b02f85f7b48b5617708;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: test-smtp-client-errors - Split off test_run_server/dns/client() from test_run_client_server(). --- diff --git a/src/lib-smtp/test-smtp-client-errors.c b/src/lib-smtp/test-smtp-client-errors.c index 6cfa5ef4f1..c19f2a5f34 100644 --- a/src/lib-smtp/test-smtp-client-errors.c +++ b/src/lib-smtp/test-smtp-client-errors.c @@ -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();