Skip to content

Commit 966e034

Browse files
committed
cc core: reorganize http2 functional tests
commit_hash:72a93c43ad811dd50876f670d47c815d3efba459
1 parent 10dbb36 commit 966e034

4 files changed

Lines changed: 241 additions & 209 deletions

File tree

.mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@
895895
"core/functional_tests/http2server/tests/test_high_level.py":"taxi/uservices/userver/core/functional_tests/http2server/tests/test_high_level.py",
896896
"core/functional_tests/http2server/tests/test_http2_streaming.py":"taxi/uservices/userver/core/functional_tests/http2server/tests/test_http2_streaming.py",
897897
"core/functional_tests/http2server/tests/test_low_level.py":"taxi/uservices/userver/core/functional_tests/http2server/tests/test_low_level.py",
898+
"core/functional_tests/http2server/tests/utils.py":"taxi/uservices/userver/core/functional_tests/http2server/tests/utils.py",
898899
"core/functional_tests/http_client_middlewares/CMakeLists.txt":"taxi/uservices/userver/core/functional_tests/http_client_middlewares/CMakeLists.txt",
899900
"core/functional_tests/http_client_middlewares/config_vars.yaml":"taxi/uservices/userver/core/functional_tests/http_client_middlewares/config_vars.yaml",
900901
"core/functional_tests/http_client_middlewares/main.cpp":"taxi/uservices/userver/core/functional_tests/http_client_middlewares/main.cpp",

core/functional_tests/http2server/tests/conftest.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
1+
import contextlib
2+
import logging
3+
import socket
4+
5+
import h2.connection
6+
import h2.events
17
import httpx
28
import pytest
39

10+
import utils
11+
412
pytest_plugins = ['pytest_userver.plugins.core']
513

614
DEFAULT_TIMEOUT = 10.0
715

816

17+
@pytest.fixture(name='create_socket')
18+
async def _create_socket(service_port, asyncio_socket):
19+
@contextlib.asynccontextmanager
20+
async def create_socket():
21+
logging.debug('Connecting to localhost:%d', service_port)
22+
try:
23+
sock = asyncio_socket.socket(socket.AF_INET, socket.SOCK_STREAM)
24+
await sock.connect(('localhost', service_port))
25+
logging.debug('Connected: %r', sock)
26+
27+
yield sock
28+
29+
finally:
30+
sock.close()
31+
32+
return create_socket
33+
34+
35+
@pytest.fixture(name='create_connection')
36+
async def _create_connection(create_socket):
37+
@contextlib.asynccontextmanager
38+
async def create_connection():
39+
conn = h2.connection.H2Connection()
40+
conn.initiate_connection()
41+
42+
async with create_socket() as sock:
43+
events = []
44+
while len(events) != 2:
45+
events += await utils.send_and_receive(sock, conn)
46+
assert isinstance(events[0], h2.events.RemoteSettingsChanged)
47+
assert utils.MAX_CONCURRENT_STREAMS == events[0].changed_settings[3].new_value
48+
assert utils.DEFAULT_FRAME_SIZE == events[0].changed_settings[5].new_value
49+
assert isinstance(events[1], h2.events.SettingsAcknowledged)
50+
51+
logging.debug('Connection successfully created')
52+
53+
yield sock, conn
54+
55+
return create_connection
56+
57+
958
class Http2Client:
1059
def __init__(self, baseurl):
1160
self.baseurl = baseurl[:-1] # rm '/'

0 commit comments

Comments
 (0)