From 9e6436fce36d97b63095e05ff7b23cd519e1e2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 16 Feb 2016 10:24:23 +0100 Subject: [PATCH] Add test for issue #1429. UDP receive timeout doesn't work for the libevent driver. (cherry picked from commit 443e0713ded4d2eaf5e9bc6c24ed79069d2a92dd) (cherry picked from commit 6997dc304c2d09511c409bd18f847bac330a06a3) --- tests/vibe.core.net.1429/dub.sdl | 4 ++++ tests/vibe.core.net.1429/source/app.d | 29 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/vibe.core.net.1429/dub.sdl create mode 100644 tests/vibe.core.net.1429/source/app.d diff --git a/tests/vibe.core.net.1429/dub.sdl b/tests/vibe.core.net.1429/dub.sdl new file mode 100644 index 0000000..5df5ea8 --- /dev/null +++ b/tests/vibe.core.net.1429/dub.sdl @@ -0,0 +1,4 @@ +name "tests" +description "TCP disconnect task issue" +dependency "vibe-d:core" path="../../" +versions "VibeDefaultMain" diff --git a/tests/vibe.core.net.1429/source/app.d b/tests/vibe.core.net.1429/source/app.d new file mode 100644 index 0000000..352e62c --- /dev/null +++ b/tests/vibe.core.net.1429/source/app.d @@ -0,0 +1,29 @@ +import vibe.core.core; +import vibe.core.log : logInfo; +import vibe.core.net; +import core.time : msecs; +import std.datetime : Clock, UTC; + +shared static this() +{ + auto udp = listenUDP(11429, "127.0.0.1"); + + runTask({ + sleep(500.msecs); + assert(false, "Receive call did not return in a timely manner. Killing process."); + }); + + runTask({ + auto start = Clock.currTime(UTC()); + try { + udp.recv(100.msecs); + assert(false, "Timeout did not occur."); + } catch (Exception e) { + auto duration = Clock.currTime(UTC()) - start; + assert(duration >= 99.msecs, "Timeout occurred too early"); + assert(duration >= 99.msecs && duration < 150.msecs, "Timeout occurred too late."); + logInfo("UDP receive timeout test was successful."); + exitEventLoop(); + } + }); +}