From 06da436a4c911596510c6753e27c288205d61d28 Mon Sep 17 00:00:00 2001 From: "hrushikesh.bhosale" Date: Tue, 25 Feb 2025 14:14:43 +0530 Subject: [PATCH] feat(http_server/async_handler): Http server async pytest was not enabled Pytest for the http_server/async_handler example was not enabled, this ensures that the pytest is enabled --- examples/protocols/.build-test-rules.yml | 8 +++ .../pytest_http_server_async.py | 52 +++++++++++++++++++ .../http_server/async_handlers/sdkconfig.ci | 3 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 examples/protocols/http_server/async_handlers/pytest_http_server_async.py diff --git a/examples/protocols/.build-test-rules.yml b/examples/protocols/.build-test-rules.yml index 844ab33ccb..cd33cb3bb8 100644 --- a/examples/protocols/.build-test-rules.yml +++ b/examples/protocols/.build-test-rules.yml @@ -60,6 +60,14 @@ examples/protocols/http_server: depends_components+: - esp_http_server +examples/protocols/http_server/async_handlers: + <<: *default_rules + disable_test: + - if: IDF_TARGET not in ["esp32"] + reason: only test on esp32 + depends_components+: + - esp_http_server + examples/protocols/http_server/captive_portal: <<: *default_rules disable+: 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 new file mode 100644 index 0000000000..1021fbbdc2 --- /dev/null +++ b/examples/protocols/http_server/async_handlers/pytest_http_server_async.py @@ -0,0 +1,52 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 +import http.client +import logging +import os +import time + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32 +@pytest.mark.ethernet +def test_http_server_async_handler(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 HTTP connection + conn_long = http.client.HTTPConnection(got_ip, got_port, timeout=15) + + # Test long URI + long_uri = '/long' + logging.info('Sending request to long URI: {}'.format(long_uri)) + conn_long.request('GET', long_uri) + dut.expect('uri: /long', timeout=30) + response_long = conn_long.getresponse() + logging.info('Response status for long URI: {}'.format(response_long.status)) + assert response_long.status == 200, 'Failed to access long URI' + + # Test quick URI + for i in range(3): + conn_quick = http.client.HTTPConnection(got_ip, got_port, timeout=15) + quick_uri = '/quick' + logging.info('Sending request to quick URI: {}'.format(quick_uri)) + conn_quick.request('GET', quick_uri) + time.sleep(1) # Adding a delay of 1 second before getting the response + response_quick = conn_quick.getresponse() + dut.expect('uri: /quick', timeout=30) + logging.info('Response status for quick URI: {}'.format(response_quick.status)) + assert response_quick.status == 200, 'Failed to access quick URI' + conn_quick.close() + + conn_long.close() diff --git a/examples/protocols/http_server/async_handlers/sdkconfig.ci b/examples/protocols/http_server/async_handlers/sdkconfig.ci index 5d82a55bd8..2fa7649111 100644 --- a/examples/protocols/http_server/async_handlers/sdkconfig.ci +++ b/examples/protocols/http_server/async_handlers/sdkconfig.ci @@ -1,2 +1,3 @@ CONFIG_EXAMPLE_MAX_ASYNC_REQUESTS=2 -CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y +CONFIG_EXAMPLE_CONNECT_WIFI=n +CONFIG_EXAMPLE_CONNECT_ETHERNET=y