From aa3e375f42d18b1becaabb0e92793f9a2366212e Mon Sep 17 00:00:00 2001 From: Luminita Voicu Date: Tue, 24 Nov 2020 13:07:45 +0200 Subject: [PATCH] tests: added limit for maximum opened connections The micro-http server holds a HashMap of all open connections and has a limit for the number of active connections at the same time. The `requests_unixsocket` python package, used by the testing framework for issuing API requests, opens a new connection for every API call and keeps it alive even after receiving the response from the server. These sockets are kept inside the connections HashMap and might very easily end up in exceeding the micro-http's limit, triggering a '503' response from the server. To prevent this from happening, the `pool_connections` argument was set to 10, consistent with the maximum number of open connections allowed. Attempts to issue a new API request, after this limit has been reached, implies closing and removing the least recently used open fd and then adding a newly opened connection to the pool. Signed-off-by: Luminita Voicu --- tests/framework/http.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/framework/http.py b/tests/framework/http.py index f3ee4a2a009..032f667f539 100644 --- a/tests/framework/http.py +++ b/tests/framework/http.py @@ -2,12 +2,13 @@ # SPDX-License-Identifier: Apache-2.0 """Wrapper over an http session with timed requests.""" # pylint: disable=unused-import -import requests_unixsocket +import requests +from requests_unixsocket import DEFAULT_SCHEME, UnixAdapter from framework import decorators -class Session(requests_unixsocket.Session): +class Session(requests.Session): """Wrapper over requests_unixsocket.Session limiting the call duration. Only the API calls relevant to Firecracker (GET, PUT, PATCH) are @@ -18,6 +19,11 @@ def __init__(self): """Create a Session object and set the is_good_response callback.""" super().__init__() + # The `pool_connections` argument indicates the maximum number of + # open connections allowed at a time. This value is set to 10 for + # consistency with the micro-http's `MAX_CONNECTIONS`. + self.mount(DEFAULT_SCHEME, UnixAdapter(pool_connections=10)) + def is_good_response(response: int): """Return `True` for all HTTP 2xx response codes.""" return 200 <= response < 300