From 52ead0891f157d21490add28a5be9ee9ddd2fa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 16 May 2017 09:40:18 +0200 Subject: [PATCH] Add test for rejectedsoftware/vibe.d#1726. --- tests/vibe.core.net.1726.d | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/vibe.core.net.1726.d diff --git a/tests/vibe.core.net.1726.d b/tests/vibe.core.net.1726.d new file mode 100644 index 0000000..55af1e4 --- /dev/null +++ b/tests/vibe.core.net.1726.d @@ -0,0 +1,67 @@ +/++ dub.sdl: + name "tests" + description "TCP disconnect task issue" + dependency "vibe-core" path="../" ++/ +module tests; + +import vibe.core.core; +import vibe.core.net; +import core.time : msecs; +import vibe.core.log; + +void main() +{ + bool done = false; + auto buf = new ubyte[512*1024*1024]; + + listenTCP(11375,(conn) { + bool read_ex = false; + bool write_ex = false; + auto rt = runTask!TCPConnection((conn) { + try { + conn.read(buf); + assert(false, "Expected read() to throw an exception."); + } catch (Exception) { + read_ex = true; + conn.close(); + logInfo("read out"); + } // expected + }, conn); + auto wt = runTask!TCPConnection((conn) { + sleep(1.msecs); // give the connection time to establish + try { + conn.write(buf); + assert(false, "Expected read() to throw an exception."); + } catch (Exception) { + write_ex = true; + conn.close(); + logInfo("write out"); + } // expected + }, conn); + + rt.join(); + wt.join(); + assert(read_ex, "No read exception thrown"); + assert(write_ex, "No write exception thrown"); + done = true; + }, "127.0.0.1"); + + runTask({ + try { + auto conn = connectTCP("127.0.0.1", 11375); + sleep(10.msecs); + conn.close(); + } catch (Exception e) assert(false, e.msg); + sleep(50.msecs); + assert(done, "Not done"); + + exitEventLoop(); + }); + + setTimer(2000.msecs, { + assert(false, "Test has hung."); + }); + + runApplication(); +}