test-http-client-errors.c (dovecot-2.3.16) | : | test-http-client-errors.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
#include "time-util.h" | #include "time-util.h" | |||
#include "sleep.h" | #include "sleep.h" | |||
#include "connection.h" | #include "connection.h" | |||
#include "test-common.h" | #include "test-common.h" | |||
#include "test-subprocess.h" | #include "test-subprocess.h" | |||
#include "http-url.h" | #include "http-url.h" | |||
#include "http-request.h" | #include "http-request.h" | |||
#include "http-client.h" | #include "http-client.h" | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <sys/signal.h> | ||||
#define CLIENT_PROGRESS_TIMEOUT 10 | #define CLIENT_PROGRESS_TIMEOUT 10 | |||
#define SERVER_KILL_TIMEOUT_SECS 20 | #define SERVER_KILL_TIMEOUT_SECS 20 | |||
static void main_deinit(void); | static void main_deinit(void); | |||
/* | /* | |||
* Types | * Types | |||
*/ | */ | |||
skipping to change at line 379 | skipping to change at line 380 | |||
/* | /* | |||
* Connection refused | * Connection refused | |||
*/ | */ | |||
/* server */ | /* server */ | |||
static void | static void | |||
test_server_connection_refused(unsigned int index ATTR_UNUSED) | test_server_connection_refused(unsigned int index ATTR_UNUSED) | |||
{ | { | |||
i_close_fd(&fd_listen); | i_close_fd(&fd_listen); | |||
test_subprocess_notify_signal_send_parent(SIGUSR1); | ||||
} | } | |||
/* client */ | /* client */ | |||
struct _connection_refused { | struct _connection_refused { | |||
unsigned int count; | unsigned int count; | |||
struct timeout *to; | struct timeout *to; | |||
}; | }; | |||
static void | static void | |||
skipping to change at line 418 | skipping to change at line 421 | |||
i_debug("TIMEOUT (ok)"); | i_debug("TIMEOUT (ok)"); | |||
timeout_remove(&ctx->to); | timeout_remove(&ctx->to); | |||
} | } | |||
static bool | static bool | |||
test_client_connection_refused(const struct http_client_settings *client_set) | test_client_connection_refused(const struct http_client_settings *client_set) | |||
{ | { | |||
struct http_client_request *hreq; | struct http_client_request *hreq; | |||
struct _connection_refused *ctx; | struct _connection_refused *ctx; | |||
/* wait for the server side to close the socket */ | ||||
test_subprocess_notify_signal_wait(SIGUSR1, 10000); | ||||
ctx = i_new(struct _connection_refused, 1); | ctx = i_new(struct _connection_refused, 1); | |||
ctx->count = 2; | ctx->count = 2; | |||
if (client_set->max_connect_attempts > 0) { | if (client_set->max_connect_attempts > 0) { | |||
ctx->to = timeout_add_short(250, | ctx->to = timeout_add_short(250, | |||
test_client_connection_refused_timeout, ctx); | test_client_connection_refused_timeout, ctx); | |||
} | } | |||
http_client = http_client_init(client_set); | http_client = http_client_init(client_set); | |||
skipping to change at line 454 | skipping to change at line 460 | |||
/* test */ | /* test */ | |||
static void test_connection_refused(void) | static void test_connection_refused(void) | |||
{ | { | |||
struct http_client_settings http_client_set; | struct http_client_settings http_client_set; | |||
test_client_defaults(&http_client_set); | test_client_defaults(&http_client_set); | |||
test_begin("connection refused"); | test_begin("connection refused"); | |||
test_subprocess_notify_signal_reset(SIGUSR1); | ||||
test_run_client_server(&http_client_set, | test_run_client_server(&http_client_set, | |||
test_client_connection_refused, | test_client_connection_refused, | |||
test_server_connection_refused, 1, NULL); | test_server_connection_refused, 1, NULL); | |||
test_end(); | test_end(); | |||
http_client_set.max_connect_attempts = 3; | http_client_set.max_connect_attempts = 3; | |||
test_begin("connection refused backoff"); | test_begin("connection refused backoff"); | |||
test_subprocess_notify_signal_reset(SIGUSR1); | ||||
test_run_client_server(&http_client_set, | test_run_client_server(&http_client_set, | |||
test_client_connection_refused, | test_client_connection_refused, | |||
test_server_connection_refused, 1, NULL); | test_server_connection_refused, 1, NULL); | |||
test_end(); | test_end(); | |||
} | } | |||
/* | /* | |||
* Connection lost prematurely | * Connection lost prematurely | |||
*/ | */ | |||
skipping to change at line 3777 | skipping to change at line 3785 | |||
return fd; | return fd; | |||
} | } | |||
static int test_run_server(struct test_server_data *data) | static int test_run_server(struct test_server_data *data) | |||
{ | { | |||
i_set_failure_prefix("SERVER[%u]: ", data->index + 1); | i_set_failure_prefix("SERVER[%u]: ", data->index + 1); | |||
if (debug) | if (debug) | |||
i_debug("PID=%s", my_pid); | i_debug("PID=%s", my_pid); | |||
test_subprocess_notify_signal_send_parent(SIGHUP); | ||||
ioloop = io_loop_create(); | ioloop = io_loop_create(); | |||
data->server_test(data->index); | data->server_test(data->index); | |||
io_loop_destroy(&ioloop); | io_loop_destroy(&ioloop); | |||
if (debug) | if (debug) | |||
i_debug("Terminated"); | i_debug("Terminated"); | |||
i_close_fd(&fd_listen); | i_close_fd(&fd_listen); | |||
i_free(bind_ports); | i_free(bind_ports); | |||
main_deinit(); | main_deinit(); | |||
skipping to change at line 3819 | skipping to change at line 3828 | |||
static void | static void | |||
test_run_client(const struct http_client_settings *client_set, | test_run_client(const struct http_client_settings *client_set, | |||
test_client_init_t client_test) | test_client_init_t client_test) | |||
{ | { | |||
i_set_failure_prefix("CLIENT: "); | i_set_failure_prefix("CLIENT: "); | |||
if (debug) | if (debug) | |||
i_debug("PID=%s", my_pid); | i_debug("PID=%s", my_pid); | |||
i_sleep_msecs(100); /* wait a little for server setup */ | ||||
ioloop = io_loop_create(); | ioloop = io_loop_create(); | |||
test_client_run(client_test, client_set); | test_client_run(client_test, client_set); | |||
io_loop_destroy(&ioloop); | io_loop_destroy(&ioloop); | |||
if (debug) | if (debug) | |||
i_debug("Terminated"); | i_debug("Terminated"); | |||
} | } | |||
static void | static void | |||
test_run_client_server(const struct http_client_settings *client_set, | test_run_client_server(const struct http_client_settings *client_set, | |||
test_client_init_t client_test, | test_client_init_t client_test, | |||
test_server_init_t server_test, | test_server_init_t server_test, | |||
unsigned int server_tests_count, | unsigned int server_tests_count, | |||
test_dns_init_t dns_test) | test_dns_init_t dns_test) | |||
{ | { | |||
unsigned int i; | unsigned int i; | |||
test_subprocess_notify_signal_reset(SIGHUP); | ||||
test_server_init = NULL; | test_server_init = NULL; | |||
test_server_deinit = NULL; | test_server_deinit = NULL; | |||
test_server_input = NULL; | test_server_input = NULL; | |||
if (server_tests_count > 0) { | if (server_tests_count > 0) { | |||
int fds[server_tests_count]; | int fds[server_tests_count]; | |||
bind_ports = i_new(in_port_t, server_tests_count); | bind_ports = i_new(in_port_t, server_tests_count); | |||
for (i = 0; i < server_tests_count; i++) | for (i = 0; i < server_tests_count; i++) | |||
fds[i] = test_open_server_fd(&bind_ports[i]); | fds[i] = test_open_server_fd(&bind_ports[i]); | |||
skipping to change at line 3860 | skipping to change at line 3868 | |||
struct test_server_data data; | struct test_server_data data; | |||
i_zero(&data); | i_zero(&data); | |||
data.index = i; | data.index = i; | |||
data.server_test = server_test; | data.server_test = server_test; | |||
/* Fork server */ | /* Fork server */ | |||
fd_listen = fds[i]; | fd_listen = fds[i]; | |||
test_subprocess_fork(test_run_server, &data, FALSE); | test_subprocess_fork(test_run_server, &data, FALSE); | |||
i_close_fd(&fd_listen); | i_close_fd(&fd_listen); | |||
test_subprocess_notify_signal_wait(SIGHUP, 10000); | ||||
test_subprocess_notify_signal_reset(SIGHUP); | ||||
} | } | |||
} | } | |||
if (dns_test != NULL) { | if (dns_test != NULL) { | |||
int fd; | int fd; | |||
i_unlink_if_exists("./dns-test"); | i_unlink_if_exists("./dns-test"); | |||
fd = net_listen_unix("./dns-test", 128); | fd = net_listen_unix("./dns-test", 128); | |||
if (fd == -1) { | if (fd == -1) { | |||
i_fatal("listen(./dns-test) failed: %m"); | i_fatal("listen(./dns-test) failed: %m"); | |||
End of changes. 9 change blocks. | ||||
2 lines changed or deleted | 12 lines changed or added |