From cb6a79a86fb86663f4ba4e3ad32fcd4f2e27f9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 20 Jan 2019 11:16:53 +0100 Subject: [PATCH] Make the test for #115 actually fail if a socket gets leaked. --- tests/issue-115-connect-fail-leak.d | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/issue-115-connect-fail-leak.d b/tests/issue-115-connect-fail-leak.d index 196f9db..9af3afc 100644 --- a/tests/issue-115-connect-fail-leak.d +++ b/tests/issue-115-connect-fail-leak.d @@ -8,8 +8,15 @@ import vibe.core.core; import vibe.core.log; import vibe.core.net; +import core.time; + + void main() { + // make sure that the internal driver is initialized, so that + // base resources are all allocated + sleep(1.msecs); + auto initial = determineSocketCount(); TCPConnection conn; @@ -26,6 +33,7 @@ void main() size_t determineSocketCount() { import std.algorithm.searching : count; + import std.exception : enforce; import std.range : iota; version (Posix) { @@ -34,7 +42,7 @@ size_t determineSocketCount() rlimit rl; enforce(getrlimit(RLIMIT_NOFILE, &rl) == 0); - return iota(rl.rlim_cur).count(fd => fcntl(fd, F_GETFD) != -1); + return iota(rl.rlim_cur).count!((fd) => fcntl(cast(int)fd, F_GETFD) != -1); } else { import core.sys.windows.winsock2 : getsockopt, SOL_SOCKET, SO_TYPE;