vibe-core/tests/vibe.core.net.1429.d

38 lines
861 B
D
Raw Normal View History

/+ dub.sdl:
name "test"
description "TCP disconnect task issue"
2016-10-24 06:37:32 +00:00
dependency "vibe-core" path="../"
+/
module test;
import vibe.core.core;
import vibe.core.log : logInfo;
import vibe.core.net;
2018-12-23 21:22:53 +00:00
import core.time : MonoTime, msecs;
2016-06-18 06:19:06 +00:00
void main()
{
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({
2018-12-23 21:22:53 +00:00
auto start = MonoTime.currTime();
try {
udp.recv(100.msecs);
assert(false, "Timeout did not occur.");
} catch (Exception e) {
2018-12-23 21:22:53 +00:00
auto duration = MonoTime.currTime() - 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();
}
});
2016-06-18 06:19:06 +00:00
runEventLoop();
}