mock mkdir instead of messing up node initialization; add integration marker

This commit is contained in:
gmega 2024-11-27 13:52:04 -03:00
parent ccfc7614a7
commit 205d12ebe7
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18
5 changed files with 22 additions and 7 deletions

View File

@ -52,6 +52,8 @@ class DelugeNode(SharedFSNode[Torrent, DelugeMeta]):
super().__init__(self.downloads_root)
self._init_folders()
def wipe_all_torrents(self):
torrent_ids = list(self.rpc.core.get_torrents_status({}, []).keys())
if torrent_ids:
@ -62,6 +64,7 @@ class DelugeNode(SharedFSNode[Torrent, DelugeMeta]):
# Wipe download folder to get rid of files that got uploaded but failed
# seeding or deletes.
shutil.rmtree(self.downloads_root)
self._init_folders()
def seed(
@ -107,7 +110,6 @@ class DelugeNode(SharedFSNode[Torrent, DelugeMeta]):
@property
def rpc(self) -> DelugeRPCClient:
if self._rpc is None:
self._init_folders()
self.connect()
return self._rpc

View File

@ -1,4 +1,5 @@
from io import StringIO
from unittest.mock import patch
import yaml
@ -54,7 +55,11 @@ def test_should_build_experiment_from_config():
""")
config = DelugeExperimentConfig.model_validate(yaml.safe_load(config_file)['deluge_experiment'])
experiment = config.build()
# Need to patch mkdir, or we'll try to actually create the folder when DelugeNode gets initialized.
with patch('pathlib.Path.mkdir'):
experiment = config.build()
assert len(experiment.nodes) == 10

View File

@ -1,11 +1,12 @@
from pathlib import Path
import pytest
from urllib3.util import Url
from benchmarks.core.utils import megabytes
from benchmarks.deluge.deluge_node import DelugeNode, DelugeMeta
@pytest.mark.integration
def assert_is_seed(node: DelugeNode, name: str, size: int):
response = node.torrent_info(name=name)
assert len(response) == 1
@ -15,14 +16,14 @@ def assert_is_seed(node: DelugeNode, name: str, size: int):
assert info[b'total_size'] == size
assert info[b'is_seed'] == True
@pytest.mark.integration
def test_should_seed_files(deluge_node1: DelugeNode, temp_random_file: Path, tracker: Url):
assert not deluge_node1.torrent_info(name='dataset1')
deluge_node1.seed(temp_random_file, DelugeMeta(name='dataset1', announce_url=tracker))
assert_is_seed(deluge_node1, name='dataset1', size=megabytes(1))
@pytest.mark.integration
def test_should_download_files(
deluge_node1: DelugeNode, deluge_node2: DelugeNode,
temp_random_file: Path, tracker: Url):

View File

@ -1,9 +1,11 @@
import pytest
from benchmarks.core.experiments.static_experiment import StaticDisseminationExperiment
from benchmarks.core.utils import RandomTempData, megabytes
from benchmarks.deluge.deluge_node import DelugeMeta
from benchmarks.deluge.tests.test_deluge_node import assert_is_seed
@pytest.mark.integration
def test_should_run_with_a_single_seeder(tracker, deluge_node1, deluge_node2, deluge_node3):
size = megabytes(10)
experiment = StaticDisseminationExperiment(
@ -21,7 +23,7 @@ def test_should_run_with_a_single_seeder(tracker, deluge_node1, deluge_node2, de
assert_is_seed(deluge_node2, 'dataset-1', size)
assert_is_seed(deluge_node3, 'dataset-1', size)
@pytest.mark.integration
def test_should_run_with_multiple_seeders(tracker, deluge_node1, deluge_node2, deluge_node3):
size = megabytes(10)
experiment = StaticDisseminationExperiment(

View File

@ -20,6 +20,11 @@ pytest = "^8.3.3"
mypy = "^1.13.0"
types-pyyaml = "^6.0.12.20240917"
[tool.pytest.ini_options]
markers = [
"integration: marks tests as integration tests"
]
[tool.mypy]
ignore_missing_imports = true