tests/net_inet: Add tests for accept and connect in nonblocking mode.

Some of these tests don't require an Internet connection, but here is a
good place to put them for now.
This commit is contained in:
Damien George 2017-06-21 12:25:10 +10:00
parent 4caa27ae0e
commit 458cbacb8f
6 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,16 @@
# test that socket.accept() on a non-blocking socket raises EAGAIN
try:
import usocket as socket
except:
import socket
s = socket.socket()
s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1])
s.setblocking(False)
s.listen(1)
try:
s.accept()
except OSError as er:
print(er.args[0] == 11) # 11 is EAGAIN
s.close()

View File

@ -0,0 +1 @@
True

View File

@ -0,0 +1,22 @@
# test that socket.accept() on a socket with timeout raises ETIMEDOUT
try:
import usocket as socket
except:
import socket
try:
socket.socket.settimeout
except AttributeError:
print('SKIP')
raise SystemExit
s = socket.socket()
s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1])
s.settimeout(1)
s.listen(1)
try:
s.accept()
except OSError as er:
print(er.args[0] in (110, 'timed out')) # 110 is ETIMEDOUT; CPython uses a string
s.close()

View File

@ -0,0 +1 @@
True

View File

@ -0,0 +1,14 @@
# test that socket.connect() on a non-blocking socket raises EINPROGRESS
try:
import usocket as socket
except:
import socket
s = socket.socket()
s.setblocking(False)
try:
s.connect(socket.getaddrinfo('micropython.org', 80)[0][-1])
except OSError as er:
print(er.args[0] == 115) # 115 is EINPROGRESS
s.close()

View File

@ -0,0 +1 @@
True