From c7eb76b69f75469f029a450904984328e8b7e78a Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 21 Feb 2023 22:58:24 +0700 Subject: [PATCH] Fix tests --- .../core/components/restapi/rest/events_endpoint.py | 5 +---- .../core/components/restapi/rest/rest_endpoint.py | 11 ++++++++--- .../core/components/restapi/rest/shutdown_endpoint.py | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/tribler/core/components/restapi/rest/events_endpoint.py b/src/tribler/core/components/restapi/rest/events_endpoint.py index 30f4e9364e6..6a3b311d437 100644 --- a/src/tribler/core/components/restapi/rest/events_endpoint.py +++ b/src/tribler/core/components/restapi/rest/events_endpoint.py @@ -69,10 +69,7 @@ def on_circuit_removed(self, circuit: Circuit, additional_info: str): additional_info=additional_info) async def on_shutdown(self, _): - await self.shutdown_task_manager() - - async def shutdown(self): - await self.shutdown_task_manager() + await self.shutdown() def setup_routes(self): self.app.add_routes([web.get('', self.get_events)]) diff --git a/src/tribler/core/components/restapi/rest/rest_endpoint.py b/src/tribler/core/components/restapi/rest/rest_endpoint.py index cc397c317a6..fd891483974 100644 --- a/src/tribler/core/components/restapi/rest/rest_endpoint.py +++ b/src/tribler/core/components/restapi/rest/rest_endpoint.py @@ -2,12 +2,16 @@ import json import logging -from typing import Dict +from typing import Dict, TYPE_CHECKING from aiohttp import web from tribler.core.utilities.async_group import AsyncGroup +if TYPE_CHECKING: + from tribler.core.components.restapi.rest.events_endpoint import EventsEndpoint + from ipv8.REST.root_endpoint import RootEndpoint as IPV8RootEndpoint + HTTP_BAD_REQUEST = 400 HTTP_UNAUTHORIZED = 401 HTTP_NOT_FOUND = 404 @@ -26,13 +30,14 @@ def __init__(self, middlewares=()): def setup_routes(self): pass - def add_endpoint(self, prefix: str, endpoint: RESTEndpoint): + def add_endpoint(self, prefix: str, endpoint: RESTEndpoint | EventsEndpoint | IPV8RootEndpoint): self.endpoints[prefix] = endpoint self.app.add_subapp(prefix, endpoint.app) async def shutdown(self): for endpoint in self.endpoints.values(): - await endpoint.shutdown() + if isinstance(endpoint, RESTEndpoint): # IPV8RootEndpoint doesn't have a shutdown method + await endpoint.shutdown() await self.async_group.cancel() diff --git a/src/tribler/core/components/restapi/rest/shutdown_endpoint.py b/src/tribler/core/components/restapi/rest/shutdown_endpoint.py index 1046fae7b29..c4b7d613e48 100644 --- a/src/tribler/core/components/restapi/rest/shutdown_endpoint.py +++ b/src/tribler/core/components/restapi/rest/shutdown_endpoint.py @@ -18,7 +18,7 @@ def __init__(self, shutdown_callback): self.shutdown_callback = shutdown_callback def setup_routes(self): - self.app.add_routes([web.put('', self.shutdown)]) + self.app.add_routes([web.put('', self.shutdown_request)]) @docs( tags=["General"], @@ -31,7 +31,7 @@ def setup_routes(self): } } ) - async def shutdown(self, request): + async def shutdown_request(self, _): self._logger.info('Received a shutdown request from GUI') self.shutdown_callback() return RESTResponse({"shutdown": True})