Files
micropython/tests/extmod/socket_udp_nonblock.py
Yanfeng Liu 274306860b tests/extmod: Close UDP sockets at end of test.
This adds call to release UDP port in a timely manner, so they can be
reused in subsequent tests.  Otherwise, one could face issue like #17623.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2025-07-15 13:57:21 +10:00

24 lines
414 B
Python

# test non-blocking UDP sockets
try:
import socket, errno
except ImportError:
print("SKIP")
raise SystemExit
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0][-1])
except OSError:
print("SKIP")
raise SystemExit
s.settimeout(0)
try:
s.recv(1)
except OSError as er:
print("EAGAIN:", er.errno == errno.EAGAIN)
s.close()