tests: net: lib: http_server: core: Extend start/stop test

Ensure it's possible to restart the server w/o issues after a client
connected.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2024-07-17 15:46:59 +02:00 committed by Anas Nashif
commit ff65815a3b
2 changed files with 17 additions and 0 deletions

View file

@ -43,6 +43,7 @@ CONFIG_HTTP_SERVER=y
CONFIG_HTTP_SERVER_MAX_CLIENTS=5
CONFIG_HTTP_SERVER_MAX_STREAMS=5
CONFIG_HTTP_SERVER_RESTART_DELAY=10
# Network address config
CONFIG_NET_CONFIG_SETTINGS=n

View file

@ -254,6 +254,22 @@ ZTEST(server_function_tests_no_init, test_http_server_start_stop)
zassert_ok(zsock_close(client_fd), "close() failed on the client fd (%d)", errno);
client_fd = -1;
/* Check if the server can be restarted again after client connected. */
zassert_ok(http_server_stop(), "Failed to stop the server");
zassert_ok(http_server_start(), "Failed to start the server");
/* Let the server thread run. */
k_msleep(CONFIG_HTTP_SERVER_RESTART_DELAY + 10);
ret = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
zassert_not_equal(ret, -1, "failed to create client socket (%d)", errno);
client_fd = ret;
zassert_ok(zsock_connect(client_fd, (struct sockaddr *)&sa, sizeof(sa)),
"failed to connect to the server (%d)", errno);
zassert_ok(zsock_close(client_fd), "close() failed on the client fd (%d)", errno);
client_fd = -1;
zassert_ok(http_server_stop(), "Failed to stop the server");
}