(*, host='127.0.0.1', port=0)
| 280 | |
| 281 | @contextlib.contextmanager |
| 282 | def run_udp_echo_server(*, host='127.0.0.1', port=0): |
| 283 | addr_info = socket.getaddrinfo(host, port, type=socket.SOCK_DGRAM) |
| 284 | family, type, proto, _, sockaddr = addr_info[0] |
| 285 | sock = socket.socket(family, type, proto) |
| 286 | sock.bind((host, port)) |
| 287 | sockname = sock.getsockname() |
| 288 | thread = threading.Thread(target=lambda: echo_datagrams(sock)) |
| 289 | thread.start() |
| 290 | try: |
| 291 | yield sockname |
| 292 | finally: |
| 293 | # gh-122187: use a separate socket to send the stop message to avoid |
| 294 | # TSan reported race on the same socket. |
| 295 | sock2 = socket.socket(family, type, proto) |
| 296 | sock2.sendto(b'STOP', sockname) |
| 297 | sock2.close() |
| 298 | thread.join() |
| 299 | |
| 300 | |
| 301 | def make_test_protocol(base): |
nothing calls this directly
no test coverage detected
searching dependent graphs…