Skip to content

Commit f5eb886

Browse files
committed
regress/185-pollset.lua: Add test case for :pollset()
1 parent dd61764 commit f5eb886

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

regress/185-pollset.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
_=[[
3+
. "${0%%/*}/regress.sh"
4+
exec runlua "$0" "$@"
5+
]]
6+
require"regress".export".*"
7+
8+
local cq = cqueues.new()
9+
local rd, wr = check(socket.pair())
10+
local pre_poll = false
11+
local post_poll = false
12+
cq:wrap(function()
13+
pre_poll = true
14+
cqueues.poll({
15+
pollfd = rd:pollfd();
16+
events = "r";
17+
})
18+
post_poll = true
19+
end)
20+
assert(cq:step(0))
21+
check(pre_poll and not post_poll)
22+
23+
local r, w, p = cq:pollset()
24+
check(r.n == 1 and r[1] == rd:pollfd(), "read set doesn't contain expected values")
25+
check(w.n == 0, "write set doesn't contain expected values")
26+
check(p.n == 0, "priority set doesn't contain expected values")
27+
28+
assert(cq:step(0))
29+
check(not post_poll, "Thread was unexpectedly advanced")
30+
31+
cqueues.cancel(rd)
32+
assert(cq:step(0))
33+
34+
check(post_poll, "Thread wasn't advanced")
35+
36+
say("OK")

0 commit comments

Comments
 (0)