From 38a4e4ca5f4d1d0e4f1925ab44a634c57fffeae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 26 Oct 2018 15:41:18 +0200 Subject: [PATCH] Test leaking handles through the GC. --- tests/0-leaked-handles.d | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/0-leaked-handles.d diff --git a/tests/0-leaked-handles.d b/tests/0-leaked-handles.d new file mode 100644 index 0000000..e2a2e19 --- /dev/null +++ b/tests/0-leaked-handles.d @@ -0,0 +1,36 @@ +/++ dub.sdl: + name "test" + dependency "eventcore" path=".." ++/ +module test; + +import eventcore.core; +import eventcore.driver; +import std.socket : InternetAddress; + + +class C { + DatagramSocketFD m_handle; + EventDriver m_driver; + + this() + { + auto addr = new InternetAddress(0x7F000001, 40001); + m_handle = eventDriver.sockets.createDatagramSocket(addr, null); + assert(m_handle != DatagramSocketFD.invalid); + m_driver = eventDriver; + } + + ~this() + { + assert(eventDriver is m_driver); + eventDriver.sockets.releaseRef(m_handle); + } +} + +void main() +{ + // let the GC clean up at app exit + // note that this happens *after* the static module destructors have been run + new C; +}