Skip to content

Commit

Permalink
Merge pull request #2 from qstokkink/upd_get_task
Browse files Browse the repository at this point in the history
Use new get_task functionality in tests
  • Loading branch information
qstokkink committed Apr 11, 2024
2 parents 5a877d8 + 2bc1c2e commit 99d7e87
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unittests.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.7'
python-version: '3.8'
cache: 'pip'
- run: python -m pip install -r requirements.txt
- name: Run unit tests
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.8'
cache: 'pip'
- run: python -m pip install -r requirements.txt
- name: Run unit tests
Expand Down
Expand Up @@ -363,9 +363,7 @@ async def test_download_manager_start(self) -> None:
self.manager.start()
await sleep(0)

for task in self.manager.get_tasks():
if task.get_name() == "start":
await task
await self.manager.get_task("start")

self.assertTrue(self.manager.all_checkpoints_are_loaded)

Expand Down
18 changes: 5 additions & 13 deletions src/tribler/test_unit/core/tunnel/test_community.py
@@ -1,7 +1,7 @@
from __future__ import annotations

from asyncio import TimeoutError as AsyncTimeoutError
from asyncio import sleep, wait_for
from asyncio import gather, sleep, wait_for
from collections import defaultdict
from io import BytesIO
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -198,9 +198,7 @@ async def test_monitor_downloads_stop_ip(self) -> None:
self.overlay(0).download_states[b'a'] = 3

self.overlay(0).monitor_downloads([])
for task in self.overlay(0).get_tasks():
if task.get_name().startswith("TriblerTunnelCommunity:remove_circuit"):
await task
await gather(*self.overlay(0).get_anonymous_tasks("remove_circuit"))

self.assertNotIn(0, self.overlay(0).circuits)

Expand Down Expand Up @@ -250,9 +248,7 @@ async def test_monitor_downloads_intro(self) -> None:
self.overlay(0).download_states[b'a'] = 3

self.overlay(0).monitor_downloads([])
for task in self.overlay(0).get_tasks():
if task.get_name().startswith("TriblerTunnelCommunity:remove_circuit"):
await task
await gather(*self.overlay(0).get_anonymous_tasks("remove_circuit"))

self.assertNotIn(0, self.overlay(0).circuits)

Expand All @@ -271,9 +267,7 @@ async def test_monitor_downloads_stop_all(self) -> None:
self.overlay(0).download_states[b"a"] = 3

self.overlay(0).monitor_downloads([])
for task in self.overlay(0).get_tasks():
if task.get_name().startswith("TriblerTunnelCommunity:remove_circuit"):
await task
await gather(*self.overlay(0).get_anonymous_tasks("remove_circuit"))

self.assertNotIn(0, self.overlay(0).circuits)

Expand Down Expand Up @@ -372,9 +366,7 @@ async def test_perform_http_request_not_allowed(self) -> None:
await self.introduce_nodes()
self.overlay(0).create_circuit(1, exit_flags=[PEER_FLAG_EXIT_HTTP])
await sleep(0)
for task in self.overlay(1).get_tasks():
if task.get_name().startswith("TriblerTunnelCommunity:on_packet_from_circuit"):
await task
await gather(*self.overlay(1).get_anonymous_tasks("on_packet_from_circuit"))

with patch.dict(tribler.core.tunnel.community.__dict__, {"open_connection": open_connection}),\
self.assertRaises(AsyncTimeoutError):
Expand Down

0 comments on commit 99d7e87

Please sign in to comment.