aboutsummaryrefslogtreecommitdiff
path: root/src/testing/nuts.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-07 15:45:15 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-07 15:45:15 -0800
commit45ad63d265261203155c882ec93b80a604e9ab3b (patch)
treeeb6fda615bb65e888a0bada3ad1730daabb72129 /src/testing/nuts.h
parent32c78f7b7b4fcfacea6b45e8601c82771f1e40b3 (diff)
downloadnng-45ad63d265261203155c882ec93b80a604e9ab3b.tar.gz
nng-45ad63d265261203155c882ec93b80a604e9ab3b.tar.bz2
nng-45ad63d265261203155c882ec93b80a604e9ab3b.zip
nuts: try to avoid address in use for most tests
We get test failures somewhat frequently due to port conflicts. This attempts to make more of the tests use the trick of binding to port 0, and letting us use the random port instead.
Diffstat (limited to 'src/testing/nuts.h')
-rw-r--r--src/testing/nuts.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/testing/nuts.h b/src/testing/nuts.h
index 5fe193db..f2e50c2c 100644
--- a/src/testing/nuts.h
+++ b/src/testing/nuts.h
@@ -85,6 +85,10 @@ extern uint16_t nuts_next_port(void);
// 64 bytes to ensure no truncation occurs.
extern void nuts_scratch_addr(const char *, size_t, char *);
+// like nuts_scratch_addr, but attempts to use an autobind (0 port)
+// address instead.
+extern void nuts_scratch_addr_zero(const char *, size_t, char *);
+
// nuts_marry connects two sockets using inproc. It uses socket
// pipe hooks to ensure that it does not return before both sockets
// are fully connected.
@@ -264,6 +268,14 @@ extern const char *nuts_ecdsa_client_crt;
(var) = nuts_addr_; \
} while (0)
+#define NUTS_ADDR_ZERO(var, scheme) \
+ do { \
+ static char nuts_addr_[64]; \
+ nuts_scratch_addr_zero( \
+ scheme, sizeof(nuts_addr_), nuts_addr_); \
+ (var) = nuts_addr_; \
+ } while (0)
+
#define NUTS_OPEN(sock) NUTS_PASS(nng_pair1_open(&(sock)))
#define NUTS_CLOSE(sock) NUTS_PASS(nng_close(sock))