Skip to content

Commit 17a1a0d

Browse files
hrushikesh430mahavirj
authored andcommitted
feat(async_handler): Adding test for long uri requests
Adding test for two /long async requests.
1 parent b6d4fa2 commit 17a1a0d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

examples/protocols/http_server/async_handlers/pytest_http_server_async.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,57 @@
1010
from pytest_embedded_idf.utils import idf_parametrize
1111

1212

13+
@pytest.mark.ethernet
14+
@idf_parametrize('target', ['esp32'], indirect=['target'])
15+
def test_http_server_async_handler_multiple_long_requests(dut: Dut) -> None:
16+
# Get binary file
17+
binary_file = os.path.join(dut.app.binary_path, 'simple.bin')
18+
bin_size = os.path.getsize(binary_file)
19+
logging.info('http_server_bin_size : {}KB'.format(bin_size // 1024))
20+
logging.info('Waiting to connect with Ethernet')
21+
22+
# Parse IP address of Ethernet
23+
got_ip = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode()
24+
got_port = 80 # Assuming the server is running on port 80
25+
logging.info('Got IP : {}'.format(got_ip))
26+
logging.info('Connecting to server at {}:{}'.format(got_ip, got_port))
27+
28+
# Create two HTTP connections for long requests
29+
conn_long1 = http.client.HTTPConnection(got_ip, got_port, timeout=30)
30+
conn_long2 = http.client.HTTPConnection(got_ip, got_port, timeout=30)
31+
32+
# Test first long URI with Host header and query param
33+
long_uri1 = '/long?param=async1'
34+
headers1 = {'Host': 'testhost1'}
35+
logging.info('Sending first long request with Host header and query param')
36+
conn_long1.request('GET', long_uri1, headers=headers1)
37+
38+
# Test second long URI with Host header and query param
39+
long_uri2 = '/long?param=async2'
40+
headers2 = {'Host': 'testhost2'}
41+
logging.info('Sending second long request with Host header and query param')
42+
conn_long2.request('GET', long_uri2, headers=headers2)
43+
44+
# Verify both requests are processed
45+
dut.expect('Found header => Host: testhost1', timeout=30)
46+
dut.expect('Found query string => param=async1', timeout=30)
47+
dut.expect('Found header => Host: testhost2', timeout=30)
48+
dut.expect('Found query string => param=async2', timeout=30)
49+
50+
# Get responses
51+
response_long1 = conn_long1.getresponse()
52+
response_long2 = conn_long2.getresponse()
53+
54+
logging.info('Response status for first long URI: {}'.format(response_long1.status))
55+
logging.info('Response status for second long URI: {}'.format(response_long2.status))
56+
57+
assert response_long1.status == 200, 'Failed to access first long URI'
58+
assert response_long2.status == 200, 'Failed to access second long URI'
59+
60+
conn_long1.close()
61+
conn_long2.close()
62+
63+
1364
@pytest.mark.ethernet
1465
@idf_parametrize('target', ['esp32'], indirect=['target'])
1566
def test_http_server_async_handler(dut: Dut) -> None:

0 commit comments

Comments
 (0)