From 50fe0b28b5412148cfe2cd7e495cd46582c4578f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 18 Dec 2017 11:16:59 +0100 Subject: [PATCH] Add watchdog timer and log output to flaky test. --- tests/0-tcp.d | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/0-tcp.d b/tests/0-tcp.d index 92708f4..fa79fdf 100644 --- a/tests/0-tcp.d +++ b/tests/0-tcp.d @@ -6,14 +6,20 @@ module test; import eventcore.core; import eventcore.socket; +import eventcore.internal.utils : print; import std.socket : InternetAddress; -import core.time : Duration; +import core.time : Duration, msecs; ubyte[256] s_rbuf; bool s_done; void main() { + // watchdog timer in case of starvation/deadlocks + auto tm = eventDriver.timers.create(); + eventDriver.timers.set(tm, 10000.msecs, 0.msecs); + eventDriver.timers.wait(tm, (tm) { assert(false, "Test hung."); }); + static ubyte[] pack1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; static ubyte[] pack2 = [4, 3, 2, 1, 0]; @@ -24,33 +30,46 @@ void main() server.waitForConnections!((incoming_, addr) { incoming = incoming_; // work around ref counting issue + print("Got incoming, reading data"); incoming.read!((status, bts) { + print("Got data"); assert(status == IOStatus.ok); assert(bts == pack1.length); assert(s_rbuf[0 .. pack1.length] == pack1); + print("Second write"); client.write!((status, bytes) { + print("Second write done"); assert(status == IOStatus.ok); assert(bytes == pack2.length); })(pack2, IOMode.once); + print("Second read"); incoming.read!((status, bts) { + print("Second read done"); assert(status == IOStatus.ok); assert(bts == pack2.length); assert(s_rbuf[0 .. pack2.length] == pack2); + destroy(client); destroy(incoming); destroy(server); - destroy(client); s_done = true; + eventDriver.timers.stop(tm); + + // NOTE: one reference to incoming is still held by read() + //assert(eventDriver.core.waiterCount == 1); })(s_rbuf, IOMode.once); })(s_rbuf, IOMode.once); }); + print("Connect..."); connectStream!((sock, status) { client = sock; assert(status == ConnectStatus.connected); + print("Initial write"); client.write!((wstatus, bytes) { + print("Initial write done"); assert(wstatus == IOStatus.ok); assert(bytes == 10); })(pack1, IOMode.all);