-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathtest_rsgi.py
79 lines (59 loc) · 2.6 KB
/
test_rsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import httpx
import pytest
@pytest.mark.asyncio
@pytest.mark.skipif(bool(os.getenv('PGO_RUN')), reason='PGO build')
@pytest.mark.parametrize('runtime_mode', ['mt', 'st'])
async def test_scope(rsgi_server, runtime_mode):
async with rsgi_server(runtime_mode) as port:
res = httpx.get(f'http://localhost:{port}/info?test=true')
assert res.status_code == 200
assert res.headers['content-type'] == 'application/json'
data = res.json()
assert data['proto'] == 'http'
assert data['http_version'] == '1.1'
assert data['rsgi_version'] == '1.4'
assert data['scheme'] == 'http'
assert data['method'] == 'GET'
assert data['path'] == '/info'
assert data['query_string'] == 'test=true'
assert data['headers']['host'] == f'localhost:{port}'
assert not data['authority']
@pytest.mark.asyncio
@pytest.mark.parametrize('runtime_mode', ['mt', 'st'])
async def test_body(rsgi_server, runtime_mode):
async with rsgi_server(runtime_mode) as port:
res = httpx.post(f'http://localhost:{port}/echo', content='test')
assert res.status_code == 200
assert res.text == 'test'
@pytest.mark.asyncio
@pytest.mark.skipif(not bool(os.getenv('PGO_RUN')), reason='not PGO build')
@pytest.mark.parametrize('runtime_mode', ['mt', 'st'])
async def test_body_large(rsgi_server, runtime_mode):
data = ''.join([f'{idx}test'.zfill(8) for idx in range(0, 5000)])
async with rsgi_server(runtime_mode) as port:
res = httpx.post(f'http://localhost:{port}/echo', content=data)
assert res.status_code == 200
assert res.text == data
@pytest.mark.asyncio
@pytest.mark.parametrize('runtime_mode', ['mt', 'st'])
async def test_body_stream_req(rsgi_server, runtime_mode):
data = ''.join([f'{idx}test'.zfill(8) for idx in range(0, 5000)])
async with rsgi_server(runtime_mode) as port:
res = httpx.post(f'http://localhost:{port}/echos', content=data)
assert res.status_code == 200
assert res.text == data
@pytest.mark.asyncio
@pytest.mark.parametrize('runtime_mode', ['mt', 'st'])
async def test_body_stream_res(rsgi_server, runtime_mode):
async with rsgi_server(runtime_mode) as port:
res = httpx.get(f'http://localhost:{port}/stream')
assert res.status_code == 200
assert res.text == 'test' * 3
@pytest.mark.asyncio
@pytest.mark.skipif(bool(os.getenv('PGO_RUN')), reason='PGO build')
@pytest.mark.parametrize('runtime_mode', ['mt', 'st'])
async def test_app_error(rsgi_server, runtime_mode):
async with rsgi_server(runtime_mode) as port:
res = httpx.get(f'http://localhost:{port}/err_app')
assert res.status_code == 500