forked from romilly/quick2wire-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_eventfd.py
More file actions
48 lines (27 loc) · 1.33 KB
/
test_eventfd.py
File metadata and controls
48 lines (27 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from select import epoll, EPOLLIN
from contextlib import closing
from quick2wire.eventfd import Semaphore
def test_can_signal_poll_and_receive_a_semaphore():
with closing(Semaphore()) as s, closing(epoll()) as poller:
poller.register(s, EPOLLIN)
assert poller.poll(timeout=0) == []
s.signal()
assert poller.poll(timeout=0) == [(s.fileno(), EPOLLIN)]
assert poller.poll(timeout=0) == [(s.fileno(), EPOLLIN)]
assert s.wait() == True
assert poller.poll(timeout=0) == []
def test_can_initialise_a_semaphore_with_a_count():
with closing(Semaphore(1)) as s, closing(epoll()) as poller:
poller.register(s, EPOLLIN)
assert poller.poll(timeout=0) == [(s.fileno(), EPOLLIN)]
def test_a_semaphore_can_be_nonblocking():
with closing(Semaphore(blocking=False)) as s, closing(epoll()) as poller:
poller.register(s, EPOLLIN)
assert s.wait() == False
assert poller.poll(timeout=0) == []
s.signal()
assert poller.poll(timeout=0) == [(s.fileno(), EPOLLIN)]
assert poller.poll(timeout=0) == [(s.fileno(), EPOLLIN)]
assert s.wait() == True
assert s.wait() == False
assert poller.poll(timeout=0) == []