Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the get_torrent_health endpoint in GUI tests #7505

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix get_torrent_health endpoint in GUI tests
  • Loading branch information
kozlovsky committed Jun 26, 2023
commit 56595a719e550a372c648d2f54d334ea78662e0e
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 @@
# /<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 @@
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 @@
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
Loading