Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Feb 24, 2023
1 parent 7791a2a commit c7eb76b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/tribler/core/components/restapi/rest/events_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
11 changes: 8 additions & 3 deletions src/tribler/core/components/restapi/rest/rest_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions src/tribler/core/components/restapi/rest/shutdown_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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})

0 comments on commit c7eb76b

Please sign in to comment.