Add event test and fix the notify_all==false case.
This commit is contained in:
parent
5450cda724
commit
9bf0875778
|
@ -1034,7 +1034,7 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop) : EventDriverEvents {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!m_loop.m_fds[event].event.waiters.empty)
|
if (!m_loop.m_fds[event].event.waiters.empty)
|
||||||
m_loop.m_fds[event].event.waiters.consumeOne();
|
m_loop.m_fds[event].event.waiters.consumeOne()(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
69
tests/0-event.d
Normal file
69
tests/0-event.d
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/++ dub.sdl:
|
||||||
|
name "test"
|
||||||
|
dependency "eventcore" path=".."
|
||||||
|
+/
|
||||||
|
module test;
|
||||||
|
|
||||||
|
import eventcore.core;
|
||||||
|
import std.stdio : writefln;
|
||||||
|
import core.stdc.signal;
|
||||||
|
import core.time : Duration, msecs;
|
||||||
|
import core.thread : Thread;
|
||||||
|
|
||||||
|
bool s_done;
|
||||||
|
shared EventDriverEvents ss_evts;
|
||||||
|
|
||||||
|
void test(bool notify_all)
|
||||||
|
{
|
||||||
|
auto id = eventDriver.events.create();
|
||||||
|
auto tm = eventDriver.timers.create();
|
||||||
|
|
||||||
|
eventDriver.events.wait(id, (id) {
|
||||||
|
assert(!s_done);
|
||||||
|
|
||||||
|
eventDriver.events.wait(id, (id) {
|
||||||
|
assert(!s_done);
|
||||||
|
s_done = true;
|
||||||
|
eventDriver.timers.cancelWait(tm);
|
||||||
|
eventDriver.core.exit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
eventDriver.timers.set(tm, 500.msecs, 0.msecs);
|
||||||
|
eventDriver.timers.wait(tm, (tm) {
|
||||||
|
eventDriver.events.trigger(id, notify_all);
|
||||||
|
eventDriver.timers.set(tm, 500.msecs, 0.msecs);
|
||||||
|
eventDriver.timers.wait(tm, (tm) @trusted {
|
||||||
|
scope (failure) assert(false);
|
||||||
|
new Thread({
|
||||||
|
ss_evts.trigger(id, notify_all);
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
eventDriver.timers.set(tm, 500.msecs, 0.msecs);
|
||||||
|
eventDriver.timers.wait(tm, (tm) @trusted {
|
||||||
|
assert(false, "Test hung.");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ExitReason er;
|
||||||
|
do er = eventDriver.core.processEvents(Duration.max);
|
||||||
|
while (er == ExitReason.idle);
|
||||||
|
//assert(er == ExitReason.outOfWaiters); // FIXME: see above
|
||||||
|
assert(s_done);
|
||||||
|
s_done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
ss_evts = cast(shared)eventDriver.events;
|
||||||
|
test(false);
|
||||||
|
test(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(string s)
|
||||||
|
@safe nothrow {
|
||||||
|
import std.stdio : writeln;
|
||||||
|
scope (failure) assert(false);
|
||||||
|
writeln(s);
|
||||||
|
}
|
Loading…
Reference in a new issue