[master] bbff727de Merge from VTEST:

Poul-Henning Kamp phk at FreeBSD.org
Wed Aug 7 09:10:11 UTC 2019


commit bbff727de37a20c56de1be18a13d2a81b5af7191
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Aug 7 08:47:37 2019 +0000

    Merge from VTEST:
    
        Author: Frédéric Lécaille <flecaille at haproxy.com>
        Date:   Mon Jul 15 15:20:07 2019 +0200
    
        Open and close a TCP socket to simulate an unreachable server.
    
        This is done for each haproxy instance. The socket address (resp. port)
        may be referenced by ${<name>_closed_addr} (resp. ${<name>_closed_port})
        variable where <name> is the haproxy instance name.

diff --git a/bin/varnishtest/vtc_haproxy.c b/bin/varnishtest/vtc_haproxy.c
index ccd0fba80..b24af08ca 100644
--- a/bin/varnishtest/vtc_haproxy.c
+++ b/bin/varnishtest/vtc_haproxy.c
@@ -89,6 +89,7 @@ struct haproxy {
 
 	char			*workdir;
 	struct vsb		*msgs;
+	char			closed_sock[256]; /* Closed TCP socket */
 	VTAILQ_HEAD(,envar) envars;
 };
 
@@ -494,6 +495,9 @@ haproxy_new(const char *name)
 	struct haproxy *h;
 	struct vsb *vsb;
 	char buf[PATH_MAX];
+	int closed_sock;
+	char addr[128], port[128];
+	const char *err;
 
 	ALLOC_OBJ(h, HAPROXY_MAGIC);
 	AN(h);
@@ -523,6 +527,21 @@ haproxy_new(const char *name)
 	h->cfg_fn = strdup(buf);
 	AN(h->cfg_fn);
 
+	/* Create a new TCP socket to reserve an IP:port and close it asap.
+	 * May be useful to simulate an unreachable server.
+	 */
+	bprintf(h->closed_sock, "%s_closed", h->name);
+	closed_sock = VTCP_listen_on("localhost:0", NULL, 100, &err);
+	if (err != NULL)
+		vtc_fatal(h->vl,
+			"Create listen socket failed: %s", err);
+	assert(closed_sock > 0);
+	VTCP_myname(closed_sock, addr, sizeof addr, port, sizeof port);
+	macro_def(h->vl, h->closed_sock, "sock", "%s %s", addr, port);
+	macro_def(h->vl, h->closed_sock, "addr", "%s", addr);
+	macro_def(h->vl, h->closed_sock, "port", "%s", port);
+	VTCP_close(&closed_sock);
+
 	h->cli = haproxy_cli_new(h);
 	AN(h->cli);
 


More information about the varnish-commit mailing list