changeset 21335:aeadca02bfe1

lib-http: client: Added test for normal connection backoff behavior to test-http-client-errors.
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Fri, 16 Dec 2016 23:58:43 +0100
parents 919df3038bf5
children fdb33b075caa
files src/lib-http/test-http-client-errors.c
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-http/test-http-client-errors.c	Fri Dec 16 23:36:19 2016 +0100
+++ b/src/lib-http/test-http-client-errors.c	Fri Dec 16 23:58:43 2016 +0100
@@ -165,6 +165,7 @@
 
 struct _connection_refused {
 	unsigned int count;
+	struct timeout *to;
 };
 
 static void
@@ -172,6 +173,10 @@
 	const struct http_response *resp,
 	struct _connection_refused *ctx)
 {
+	test_assert(ctx->to == NULL);
+	if (ctx->to != NULL)
+		timeout_remove(&ctx->to);
+
 	if (debug)
 		i_debug("RESPONSE: %u %s", resp->status, resp->reason);
 
@@ -184,6 +189,14 @@
 	}
 }
 
+static void
+test_client_connection_refused_timeout(struct _connection_refused *ctx)
+{
+	if (debug)
+		i_debug("TIMEOUT (ok)");
+	timeout_remove(&ctx->to);
+}
+
 static bool
 test_client_connection_refused(const struct http_client_settings *client_set)
 {
@@ -193,6 +206,11 @@
 	ctx = i_new(struct _connection_refused, 1);
 	ctx->count = 2;
 
+	if (client_set->max_connect_attempts > 0) {
+		ctx->to = timeout_add_short(250,
+			test_client_connection_refused_timeout, ctx);
+	}
+
 	http_client = http_client_init(client_set);
 
 	hreq = http_client_request(http_client,
@@ -224,6 +242,15 @@
 		test_server_connection_refused, 1,
 		NULL);
 	test_end();
+
+	http_client_set.max_connect_attempts = 3;
+
+	test_begin("connection refused backoff");
+	test_run_client_server(&http_client_set,
+		test_client_connection_refused,
+		test_server_connection_refused, 1,
+		NULL);
+	test_end();
 }
 
 /*