Add tests from vibe-d:core.

This commit is contained in:
Sönke Ludwig 2017-02-17 00:55:16 +01:00
parent 99bc332a81
commit 5a8d5a2fea
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C
7 changed files with 354 additions and 0 deletions

View file

@ -0,0 +1,58 @@
/+ 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);
});
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);
logInfo("Success.");
exitEventLoop(true);
}
shared static this()
{
setLogFormat(FileLogger.Format.threadTime, FileLogger.Format.threadTime);
runTask(toDelegate(&test));
}