Mercurial > dovecot > core-2.2
changeset 20365:c0ec6c81852d
lib-http: client: Added tests for manual handling of connection loss retries to test-http-client-errors.
author | Stephan Bosch <stephan@dovecot.fi> |
---|---|
date | Fri, 17 Jun 2016 16:59:37 +0200 |
parents | 51790e6d3310 |
children | a6f71ee79262 |
files | src/lib-http/test-http-client-errors.c |
diffstat | 1 files changed, 34 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/test-http-client-errors.c Fri Jun 17 16:59:15 2016 +0200 +++ b/src/lib-http/test-http-client-errors.c Fri Jun 17 16:59:37 2016 +0200 @@ -679,17 +679,31 @@ unsigned int count; }; +struct _connection_lost_request_ctx { + struct _connection_lost_ctx *ctx; + struct http_client_request *req; +}; + static void test_client_connection_lost_response( const struct http_response *resp, - struct _connection_lost_ctx *ctx) + struct _connection_lost_request_ctx *rctx) { + struct _connection_lost_ctx *ctx = rctx->ctx; + if (debug) i_debug("RESPONSE: %u %s", resp->status, resp->reason); test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_CONNECTION_LOST); test_assert(resp->reason != NULL && *resp->reason != '\0'); + if (http_client_request_try_retry(rctx->req)) { + if (debug) + i_debug("retrying"); + return; + } + i_free(rctx); + if (--ctx->count == 0) { i_free(ctx); io_loop_stop(ioloop); @@ -704,6 +718,7 @@ "server the opportunity to close the connection before the payload " "is finished."; struct _connection_lost_ctx *ctx; + struct _connection_lost_request_ctx *rctx; struct http_client_request *hreq; struct istream *input; @@ -714,16 +729,22 @@ input = i_stream_create_from_data(payload, sizeof(payload)-1); - hreq = http_client_request(http_client, + rctx = i_new(struct _connection_lost_request_ctx, 1); + rctx->ctx = ctx; + + rctx->req = hreq = http_client_request(http_client, "GET", net_ip2addr(&bind_ip), "/connection-lost.txt", - test_client_connection_lost_response, ctx); + test_client_connection_lost_response, rctx); http_client_request_set_port(hreq, bind_ports[0]); http_client_request_set_payload(hreq, input, FALSE); http_client_request_submit(hreq); - hreq = http_client_request(http_client, + rctx = i_new(struct _connection_lost_request_ctx, 1); + rctx->ctx = ctx; + + rctx->req = hreq = http_client_request(http_client, "GET", net_ip2addr(&bind_ip), "/connection-lost2.txt", - test_client_connection_lost_response, ctx); + test_client_connection_lost_response, rctx); http_client_request_set_port(hreq, bind_ports[0]); http_client_request_submit(hreq); @@ -760,6 +781,14 @@ test_client_connection_lost, test_server_connection_lost, 1); test_end(); + + test_begin("connection lost: manual retry"); + http_client_set.max_attempts = 3; + http_client_set.no_auto_retry = TRUE; + test_run_client_server(&http_client_set, + test_client_connection_lost, + test_server_connection_lost, 1); + test_end(); } /*