Skip to content

Commit

Permalink
Fix get_torrent_health endpoint in GUI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Jun 26, 2023
1 parent 4a4b04d commit 56595a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from binascii import unhexlify
from typing import Optional

from aiohttp import ContentTypeError, web
from aiohttp_apispec import docs
from ipv8.REST.base_endpoint import HTTP_BAD_REQUEST, HTTP_NOT_FOUND
from ipv8.REST.schema import schema
from marshmallow.fields import Integer, String
from marshmallow.fields import Boolean
from pony.orm import db_session

from tribler.core.components.metadata_store.db.orm_bindings.channel_node import LEGACY_ENTRY
Expand Down Expand Up @@ -50,7 +51,7 @@ class MetadataEndpoint(MetadataEndpointBase, UpdateEntryMixin):
# /<public_key>
"""

def __init__(self, torrent_checker: TorrentChecker, *args, **kwargs):
def __init__(self, torrent_checker: Optional[TorrentChecker], *args, **kwargs):
MetadataEndpointBase.__init__(self, *args, **kwargs)
self.torrent_checker = torrent_checker

Expand Down Expand Up @@ -195,22 +196,10 @@ async def get_channel_entries(self, request):
200: {
'schema': schema(
HealthCheckResponse={
'tracker': schema(
HealthCheck={'seeders': Integer, 'leechers': Integer, 'infohash': String, 'error': String}
)
'checking': Boolean()
}
),
'examples': [
{
"health": {
"http:https://mytracker.com:80/announce": {
"seeders": 43,
"leechers": 20,
"infohash": "97d2d8f5d37e56cfaeaae151d55f05b077074779",
},
"http:https://nonexistingtracker.com:80/announce": {"error": "timeout"},
}
},
{'checking': 1},
],
}
Expand All @@ -223,7 +212,10 @@ async def get_torrent_health(self, request):
except ValueError as e:
return RESTResponse({"error": f"Error processing timeout parameter: {e}"}, status=HTTP_BAD_REQUEST)

if self.torrent_checker is None:
return RESTResponse({'checking': False})

Check warning on line 216 in src/tribler/core/components/metadata_store/restapi/metadata_endpoint.py

View check run for this annotation

Codecov / codecov/patch

src/tribler/core/components/metadata_store/restapi/metadata_endpoint.py#L216

Added line #L216 was not covered by tests

infohash = unhexlify(request.match_info['infohash'])
check_coro = self.torrent_checker.check_torrent_health(infohash, timeout=timeout, scrape_now=True)
self.async_group.add_task(check_coro)
return RESTResponse({'checking': '1'})
return RESTResponse({'checking': True})
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async def test_check_torrent_health(rest_api, mock_dlmgr, udp_tracker, metadata_
infohash = b'a' * 20
url = f'metadata/torrents/{hexlify(infohash)}/health?timeout={TORRENT_CHECK_TIMEOUT}'
json_response = await do_request(rest_api, url)
assert json_response == {'checking': '1'}
assert json_response == {'checking': True}


async def test_check_torrent_query(rest_api, udp_tracker, metadata_store):
Expand Down

0 comments on commit 56595a7

Please sign in to comment.