diff --git a/tests/0-udp.d b/tests/0-udp.d index a42f760..2a49f9e 100644 --- a/tests/0-udp.d +++ b/tests/0-udp.d @@ -7,7 +7,7 @@ module test; import eventcore.core; import eventcore.socket; import std.socket : InternetAddress; -import core.time : Duration; +import core.time : Duration, msecs; DatagramSocket s_baseSocket; DatagramSocket s_freeSocket; @@ -41,21 +41,25 @@ void main() assert(bytes == pack2.length); })(pack2, IOMode.once, baddr); - s_baseSocket.receive!((status, bts, scope addr) { - log("receive2: %s %s", status, bts); - assert(status == IOStatus.ok); - assert(bts == pack2.length); - assert(s_rbuf[0 .. pack2.length] == pack2); + auto tm = eventDriver.timers.create(); + eventDriver.timers.set(tm, 50.msecs, 0.msecs); + eventDriver.timers.wait(tm, (tm) { + s_baseSocket.receive!((status, bts, scope addr) { + log("receive2: %s %s", status, bts); + assert(status == IOStatus.ok); + assert(bts == pack2.length); + assert(s_rbuf[0 .. pack2.length] == pack2); - destroy(s_baseSocket); - destroy(s_freeSocket); - destroy(s_connectedSocket); - s_done = true; - log("done."); + destroy(s_baseSocket); + destroy(s_freeSocket); + destroy(s_connectedSocket); + s_done = true; + log("done."); - // FIXME: this shouldn't ne necessary: - eventDriver.core.exit(); - })(s_rbuf, IOMode.immediate); + // FIXME: this shouldn't be necessary: + eventDriver.core.exit(); + })(s_rbuf, IOMode.immediate); + }); })(s_rbuf, IOMode.once); s_connectedSocket.send!((status, bytes) { log("send1: %s %s", status, bytes);