From 3dc29e1d3c5572820b846b8891c4c50a8c21c113 Mon Sep 17 00:00:00 2001 From: drew2a Date: Fri, 18 Nov 2022 15:28:39 +0100 Subject: [PATCH] Add `EventsEndpoint.shutdown()` --- .../core/components/restapi/rest/events_endpoint.py | 3 +++ .../restapi/rest/tests/test_events_endpoint.py | 11 ++++++++--- .../core/components/restapi/restapi_component.py | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tribler/core/components/restapi/rest/events_endpoint.py b/src/tribler/core/components/restapi/rest/events_endpoint.py index e96cefa1745..1d63c3286a3 100644 --- a/src/tribler/core/components/restapi/rest/events_endpoint.py +++ b/src/tribler/core/components/restapi/rest/events_endpoint.py @@ -71,6 +71,9 @@ def on_circuit_removed(self, circuit: Circuit, additional_info: str): async def on_shutdown(self, _): await self.shutdown_task_manager() + async def shutdown(self): + await self.shutdown_task_manager() + def setup_routes(self): self.app.add_routes([web.get('', self.get_events)]) diff --git a/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py b/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py index 589dcdeb883..182c1c6f78f 100644 --- a/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py +++ b/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py @@ -19,6 +19,8 @@ messages_to_wait_for = set() +# pylint: disable=redefined-outer-name + @pytest.fixture(name='api_port') def fixture_api_port(free_port): return free_port @@ -29,9 +31,12 @@ def fixture_notifier(event_loop): return Notifier(loop=event_loop) -@pytest.fixture(name='endpoint') -def fixture_endpoint(notifier): - return EventsEndpoint(notifier) +@pytest.fixture +async def endpoint(notifier): + events_endpoint = EventsEndpoint(notifier) + yield events_endpoint + + await events_endpoint.shutdown() @pytest.fixture(name='reported_error') diff --git a/src/tribler/core/components/restapi/restapi_component.py b/src/tribler/core/components/restapi/restapi_component.py index fab9b55ac44..341718d7d6c 100644 --- a/src/tribler/core/components/restapi/restapi_component.py +++ b/src/tribler/core/components/restapi/restapi_component.py @@ -150,6 +150,9 @@ def report_callback(reported_error: ReportedError): async def shutdown(self): await super().shutdown() + if self._events_endpoint: + await self._events_endpoint.shutdown() + if self._core_exception_handler: self._core_exception_handler.report_callback = None