Commit e54850e9 authored by Kenton Varda's avatar Kenton Varda

Add test for UnixEventPort polling for signals (without waiting).

Cygwin seems to be having an issue with this...
parent 3a9c6665
......@@ -679,14 +679,48 @@ TEST(AsyncUnixTest, Wake) {
EXPECT_FALSE(port.wait());
}
bool woken = false;
Thread thread([&]() {
// Test wake() when already wait()ing.
{
Thread thread([&]() {
delay();
port.wake();
});
EXPECT_TRUE(port.wait());
}
// Test wait() after wake() already happened.
{
Thread thread([&]() {
port.wake();
});
delay();
woken = true;
port.wake();
});
EXPECT_TRUE(port.wait());
}
EXPECT_TRUE(port.wait());
// Test wake() during poll() busy loop.
{
Thread thread([&]() {
delay();
port.wake();
});
EXPECT_FALSE(port.poll());
while (!port.poll()) {}
}
// Test poll() when wake() already delivered.
{
EXPECT_FALSE(port.poll());
Thread thread([&]() {
port.wake();
});
delay();
EXPECT_TRUE(port.poll());
}
}
int exitCodeForSignal = 0;
......@@ -815,6 +849,30 @@ KJ_TEST("UnixEventPort whenWriteDisconnected()") {
hupPromise.wait(waitScope);
}
KJ_TEST("UnixEventPort poll for signals") {
captureSignals();
UnixEventPort port;
EventLoop loop(port);
WaitScope waitScope(loop);
auto promise1 = port.onSignal(SIGURG);
auto promise2 = port.onSignal(SIGIO);
KJ_EXPECT(!promise1.poll(waitScope));
KJ_EXPECT(!promise2.poll(waitScope));
KJ_SYSCALL(raise(SIGURG));
KJ_SYSCALL(raise(SIGIO));
port.wake();
KJ_EXPECT(port.poll());
KJ_EXPECT(promise1.poll(waitScope));
KJ_EXPECT(promise2.poll(waitScope));
promise1.wait(waitScope);
promise2.wait(waitScope);
}
} // namespace
} // namespace kj
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment