mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
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
This commit is contained in:
parent
61f992a061
commit
06da436a4c
@ -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+:
|
||||
|
@ -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()
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user