Skip to content

Commit df078e8

Browse files
committed
tests/net_hosted: Add test for socket connect() and poll() behaviour.
1 parent d5cf5f7 commit df078e8

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

tests/net_hosted/connect_poll.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# test that socket.connect() has correct polling behaviour before, during and after
2+
3+
try:
4+
import usocket as socket, uselect as select
5+
except:
6+
import socket, select
7+
8+
9+
def test(peer_addr):
10+
s = socket.socket()
11+
poller = select.poll()
12+
poller.register(s)
13+
14+
# test poll before connect
15+
# note: CPython can return POLLHUP, so use the IN|OUT mask
16+
p = poller.poll(0)
17+
print(len(p), p[0][-1] & (select.POLLIN | select.POLLOUT))
18+
19+
s.connect(peer_addr)
20+
21+
# test poll during connection
22+
print(len(poller.poll(0)))
23+
24+
# test poll after connection is established
25+
p = poller.poll(1000)
26+
print(len(p), p[0][-1])
27+
28+
s.close()
29+
30+
31+
if __name__ == "__main__":
32+
test(socket.getaddrinfo('micropython.org', 80)[0][-1])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 4
2+
1
3+
1 4

0 commit comments

Comments
 (0)