From 17a1a0dfb93bceebafc743001147ecfb7221f8fc Mon Sep 17 00:00:00 2001 From: "hrushikesh.bhosale" Date: Wed, 23 Apr 2025 14:04:57 +0530 Subject: [PATCH] feat(async_handler): Adding test for long uri requests Adding test for two /long async requests. --- .../pytest_http_server_async.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/examples/protocols/http_server/async_handlers/pytest_http_server_async.py b/examples/protocols/http_server/async_handlers/pytest_http_server_async.py index bebd7937b1..b61bcf37a5 100644 --- a/examples/protocols/http_server/async_handlers/pytest_http_server_async.py +++ b/examples/protocols/http_server/async_handlers/pytest_http_server_async.py @@ -10,6 +10,57 @@ from pytest_embedded import Dut from pytest_embedded_idf.utils import idf_parametrize +@pytest.mark.ethernet +@idf_parametrize('target', ['esp32'], indirect=['target']) +def test_http_server_async_handler_multiple_long_requests(dut: Dut) -> None: + # Get binary file + binary_file = os.path.join(dut.app.binary_path, 'simple.bin') + bin_size = os.path.getsize(binary_file) + logging.info('http_server_bin_size : {}KB'.format(bin_size // 1024)) + logging.info('Waiting to connect with Ethernet') + + # Parse IP address of Ethernet + got_ip = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode() + got_port = 80 # Assuming the server is running on port 80 + logging.info('Got IP : {}'.format(got_ip)) + logging.info('Connecting to server at {}:{}'.format(got_ip, got_port)) + + # Create two HTTP connections for long requests + conn_long1 = http.client.HTTPConnection(got_ip, got_port, timeout=30) + conn_long2 = http.client.HTTPConnection(got_ip, got_port, timeout=30) + + # Test first long URI with Host header and query param + long_uri1 = '/long?param=async1' + headers1 = {'Host': 'testhost1'} + logging.info('Sending first long request with Host header and query param') + conn_long1.request('GET', long_uri1, headers=headers1) + + # Test second long URI with Host header and query param + long_uri2 = '/long?param=async2' + headers2 = {'Host': 'testhost2'} + logging.info('Sending second long request with Host header and query param') + conn_long2.request('GET', long_uri2, headers=headers2) + + # Verify both requests are processed + dut.expect('Found header => Host: testhost1', timeout=30) + dut.expect('Found query string => param=async1', timeout=30) + dut.expect('Found header => Host: testhost2', timeout=30) + dut.expect('Found query string => param=async2', timeout=30) + + # Get responses + response_long1 = conn_long1.getresponse() + response_long2 = conn_long2.getresponse() + + logging.info('Response status for first long URI: {}'.format(response_long1.status)) + logging.info('Response status for second long URI: {}'.format(response_long2.status)) + + assert response_long1.status == 200, 'Failed to access first long URI' + assert response_long2.status == 200, 'Failed to access second long URI' + + conn_long1.close() + conn_long2.close() + + @pytest.mark.ethernet @idf_parametrize('target', ['esp32'], indirect=['target']) def test_http_server_async_handler(dut: Dut) -> None: