pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
578 B
25 lines
578 B
import gc
|
|
import weakref
|
|
|
|
from fastapi.routing import _endpoint_context_cache, _extract_endpoint_context
|
|
|
|
|
|
def _make_endpoint():
|
|
def endpoint():
|
|
return None
|
|
|
|
return endpoint
|
|
|
|
|
|
def test_endpoint_context_cache_releases_endpoints():
|
|
endpoint = _make_endpoint()
|
|
_extract_endpoint_context(endpoint)
|
|
assert endpoint in _endpoint_context_cache
|
|
|
|
ref = weakref.ref(endpoint)
|
|
size_with_endpoint = len(_endpoint_context_cache)
|
|
del endpoint
|
|
gc.collect()
|
|
|
|
assert ref() is None
|
|
assert len(_endpoint_context_cache) <= size_with_endpoint - 1
|
|
|