vibe-core/tests/vibe.core.concurrency.1408.d

59 lines
1 KiB
D
Raw Normal View History

2017-02-16 23:55:16 +00:00
/+ dub.sdl:
name "tests"
description "std.concurrency integration issue"
dependency "vibe-core" path="../"
versions "VibeDefaultMain"
+/
module test;
import vibe.core.concurrency;
import vibe.core.core;
import vibe.core.log;
import core.time : msecs;
import std.functional : toDelegate;
void test()
{
auto t = runTask({
bool gotit;
receive((int i) { assert(i == 10); gotit = true; });
assert(gotit);
sleep(10.msecs);
});
2017-02-16 23:55:16 +00:00
t.tid.send(10);
t.tid.send(11); // never received
t.join();
// ensure that recycled fibers will get a clean message queue
auto t2 = runTask({
bool gotit;
receive((int i) { assert(i == 12); gotit = true; });
assert(gotit);
});
t2.tid.send(12);
t2.join();
// test worker tasks
auto t3 = runWorkerTaskH({
bool gotit;
receive((int i) { assert(i == 13); gotit = true; });
assert(gotit);
});
t3.tid.send(13);
sleep(10.msecs);
2017-02-16 23:55:16 +00:00
logInfo("Success.");
2017-02-16 23:55:16 +00:00
exitEventLoop(true);
}
shared static this()
{
setLogFormat(FileLogger.Format.threadTime, FileLogger.Format.threadTime);
runTask(toDelegate(&test));
}