userver: samples/tcp_service/tests/test_tcp.py
Loading...
Searching...
No Matches
samples/tcp_service/tests/test_tcp.py
1# /// [Functional test]
2import socket
3
4import pytest
5
6
7async def test_basic(service_client, loop, tcp_service_port):
8 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9 sock.connect(('localhost', tcp_service_port))
10
11 await loop.sock_sendall(sock, b'hi')
12 hello = await loop.sock_recv(sock, 5)
13 assert hello == b'hello'
14
15 await loop.sock_sendall(sock, b'whats up?')
16 with pytest.raises(ConnectionResetError):
17 await loop.sock_recv(sock, 1)
18 # /// [Functional test]