eventcore/tests/0-signal.d

43 lines
951 B
D
Raw Normal View History

/++ dub.sdl:
name "test"
dependency "eventcore" path=".."
+/
module test;
import eventcore.core;
import std.stdio : writefln;
import core.stdc.signal;
import core.sys.posix.signal : SIGUSR1;
2016-10-19 20:00:06 +00:00
import core.time : Duration, msecs;
bool s_done;
void main()
{
version (OSX) writefln("Signals are not yet supported on macOS. Skipping test.");
2017-01-22 20:03:38 +00:00
else {
auto id = eventDriver.signals.listen(SIGUSR1, (id, status, sig) {
assert(!s_done);
assert(status == SignalStatus.ok);
assert(sig == () @trusted { return SIGUSR1; } ());
s_done = true;
eventDriver.core.exit();
});
auto tm = eventDriver.timers.create();
2016-10-19 20:00:06 +00:00
eventDriver.timers.set(tm, 500.msecs, 0.msecs);
eventDriver.timers.wait(tm, (tm) {
() @trusted { raise(SIGUSR1); } ();
});
ExitReason er;
2016-10-19 20:00:06 +00:00
do er = eventDriver.core.processEvents(Duration.max);
while (er == ExitReason.idle);
//assert(er == ExitReason.outOfWaiters); // FIXME: see above
assert(s_done);
s_done = false;
2017-01-22 20:03:38 +00:00
}
}