From 0ff503afa67ce13c70281dfd273b6366d1a2778b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 22 Feb 2018 15:53:44 +0100 Subject: [PATCH] Add test case for #58. --- tests/issue-58-task-already-scheduled.d | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/issue-58-task-already-scheduled.d diff --git a/tests/issue-58-task-already-scheduled.d b/tests/issue-58-task-already-scheduled.d new file mode 100644 index 0000000..2b99a38 --- /dev/null +++ b/tests/issue-58-task-already-scheduled.d @@ -0,0 +1,46 @@ +/+ dub.sdl: + name "tests" + dependency "vibe-core" path=".." ++/ +module tests; + +import vibe.core.sync; +import vibe.core.core; +import std.datetime; +import core.atomic; + +shared ManualEvent ev; +shared size_t counter; + +shared static this() +{ + ev = createSharedManualEvent(); +} + +void main() +{ + setTaskStackSize(64*1024); + + runTask({ + foreach (x; 0 .. 500) { + runWorkerTask(&worker); + } + }); + + setTimer(dur!"msecs"(10), { ev.emit(); }); + setTimer(dur!"seconds"(20), { assert(false, "Timers didn't fire within the time limit"); }); + + runApplication(); + + assert(atomicLoad(counter) == 500, "Event loop exited prematurely."); +} + +void worker() +{ + ev.wait(); + ev.emit(); + setTimer(dur!"seconds"(1), { + auto c = atomicOp!"+="(counter, 1); + if (c == 500) exitEventLoop(true); + }); +}