mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-03 18:40:59 +02:00
Merge branch 'feat/add_new_client_state_and_update_state_flow_v5.3' into 'release/v5.3'
feat(esp_http_client): added new HTTP state HTTP_STATE_CONNECTING and change state flow (v5.3) See merge request espressif/esp-idf!41278
This commit is contained in:
@@ -1691,7 +1691,7 @@ int esp_http_client_write(esp_http_client_handle_t client, const char *buffer, i
|
|||||||
|
|
||||||
esp_err_t esp_http_client_close(esp_http_client_handle_t client)
|
esp_err_t esp_http_client_close(esp_http_client_handle_t client)
|
||||||
{
|
{
|
||||||
if (client->state >= HTTP_STATE_INIT) {
|
if (client->state > HTTP_STATE_INIT) {
|
||||||
http_dispatch_event(client, HTTP_EVENT_DISCONNECTED, esp_transport_get_error_handle(client->transport), 0);
|
http_dispatch_event(client, HTTP_EVENT_DISCONNECTED, esp_transport_get_error_handle(client->transport), 0);
|
||||||
http_dispatch_event_to_event_loop(HTTP_EVENT_DISCONNECTED, &client, sizeof(esp_http_client_handle_t));
|
http_dispatch_event_to_event_loop(HTTP_EVENT_DISCONNECTED, &client, sizeof(esp_http_client_handle_t));
|
||||||
client->state = HTTP_STATE_INIT;
|
client->state = HTTP_STATE_INIT;
|
||||||
|
@@ -166,6 +166,41 @@ TEST_CASE("esp_http_client_get_url() should return URL in the correct format", "
|
|||||||
TEST_ASSERT_EQUAL_STRING(url, client_url);
|
TEST_ASSERT_EQUAL_STRING(url, client_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int disconnect_event_count = 0;
|
||||||
|
|
||||||
|
static esp_err_t disconnect_event_handler(esp_http_client_event_t *evt)
|
||||||
|
{
|
||||||
|
if (evt->event_id == HTTP_EVENT_DISCONNECTED) {
|
||||||
|
disconnect_event_count++;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("esp_http_client_close() and cleanup() should not dispatch duplicate disconnect events", "[esp_http_client]")
|
||||||
|
{
|
||||||
|
esp_http_client_config_t config = {
|
||||||
|
.url = "http://httpbin.org/get",
|
||||||
|
.event_handler = disconnect_event_handler,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reset event counter
|
||||||
|
disconnect_event_count = 0;
|
||||||
|
|
||||||
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
||||||
|
TEST_ASSERT_NOT_NULL(client);
|
||||||
|
|
||||||
|
// Close the client first
|
||||||
|
esp_err_t err = esp_http_client_close(client);
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, err);
|
||||||
|
|
||||||
|
// Then cleanup - this should not dispatch another disconnect event
|
||||||
|
err = esp_http_client_cleanup(client);
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, err);
|
||||||
|
|
||||||
|
// Verify that only one disconnect event was dispatched (or none if client was never connected)
|
||||||
|
TEST_ASSERT_LESS_OR_EQUAL(1, disconnect_event_count);
|
||||||
|
}
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
unity_run_menu();
|
unity_run_menu();
|
||||||
|
Reference in New Issue
Block a user