vibe-core/tests/issue-58-task-already-scheduled.d

48 lines
797 B
D
Raw Normal View History

2018-02-22 14:53:44 +00:00
/+ 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;
2018-02-23 14:49:49 +00:00
enum ntasks = 500;
2018-02-22 14:53:44 +00:00
shared static this()
{
ev = createSharedManualEvent();
}
void main()
{
setTaskStackSize(64*1024);
runTask({
2018-02-23 14:49:49 +00:00
foreach (x; 0 .. ntasks)
2018-02-22 14:53:44 +00:00
runWorkerTask(&worker);
});
setTimer(dur!"msecs"(10), { ev.emit(); });
2018-02-23 14:49:49 +00:00
setTimer(dur!"seconds"(60), { assert(false, "Timers didn't fire within the time limit"); });
2018-02-22 14:53:44 +00:00
runApplication();
2018-02-23 14:49:49 +00:00
assert(atomicLoad(counter) == ntasks, "Event loop exited prematurely.");
2018-02-22 14:53:44 +00:00
}
void worker()
{
ev.wait();
ev.emit();
setTimer(dur!"seconds"(1), {
auto c = atomicOp!"+="(counter, 1);
2018-02-23 14:49:49 +00:00
if (c == ntasks) exitEventLoop(true);
2018-02-22 14:53:44 +00:00
});
}