factor deluge-specific concrete implementations into its own module

This commit is contained in:
gmega 2024-11-25 16:40:36 -03:00
parent aebd070f3e
commit b706663219
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18
15 changed files with 46 additions and 18 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.pyc
.idea
.idea
/volume/deluge*

View File

@ -1 +1 @@
from benchmarks.core.tests.fixtures import *
from benchmarks.deluge.tests.fixtures import *

View File

@ -1,10 +1,8 @@
from pathlib import Path
from typing_extensions import Generic, List
from benchmarks.core.network import TInitialMetadata, TNetworkHandle, Node
from benchmarks.core.utils import Sampler, DataGenerator, DataHandle
from benchmarks.experiments.experiments import Experiment, RunnableExperiment, TRunnableExperiment
from benchmarks.core.experiments.experiments import Experiment, RunnableExperiment
class _RunnableSDE(RunnableExperiment, Generic[TNetworkHandle, TInitialMetadata]):

View File

@ -3,8 +3,8 @@ from pathlib import Path
from typing import Optional, List, Tuple, Union
from benchmarks.core.network import Node, DownloadHandle
from benchmarks.experiments.static_experiment import StaticDisseminationExperiment
from benchmarks.experiments.tests.utils import mock_sampler, MockGenerator
from benchmarks.core.experiments.static_experiment import StaticDisseminationExperiment
from benchmarks.core.experiments.tests.utils import mock_sampler, MockGenerator
@dataclass

View File

@ -1,5 +1,8 @@
import os
import random
import tempfile
from abc import ABC, abstractmethod
from contextlib import contextmanager
from dataclasses import dataclass
from pathlib import Path
from typing import Callable, Iterator, Tuple
@ -33,6 +36,18 @@ class DataGenerator(Generic[TInitialMetadata], ABC):
pass
@contextmanager
def temp_random_file(size: int, name: str = 'data.bin'):
with tempfile.TemporaryDirectory() as temp_dir_str:
temp_dir = Path(temp_dir_str)
random_file = temp_dir / name
random_bytes = os.urandom(size)
with random_file.open('wb') as outfile:
outfile.write(random_bytes)
yield random_file
def sample(n: int) -> Iterator[int]:
"""Samples without replacement using a basic Fisher-Yates shuffle."""
p = list(range(0, n))

View File

View File

@ -1,13 +1,12 @@
import os
import tempfile
from pathlib import Path
from typing import Generator
import pytest
from urllib3.util import Url, parse_url
from benchmarks.core.deluge import DelugeNode
from benchmarks.core import utils
from benchmarks.core.utils import megabytes
from benchmarks.deluge.deluge_node import DelugeNode
from benchmarks.tests.utils import shared_volume
@ -31,14 +30,13 @@ def deluge_node2() -> Generator[DelugeNode, None, None]:
@pytest.fixture
def temp_random_file() -> Generator[Path, None, None]:
with tempfile.TemporaryDirectory() as temp_dir_str:
temp_dir = Path(temp_dir_str)
random_file = temp_dir / 'data.bin'
random_bytes = os.urandom(megabytes(1))
with random_file.open('wb') as outfile:
outfile.write(random_bytes)
def deluge_node3() -> Generator[DelugeNode, None, None]:
yield from deluge_node('deluge-3', 6896)
@pytest.fixture
def temp_random_file() -> Generator[Path, None, None]:
with utils.temp_random_file(size=megabytes(1)) as random_file:
yield random_file

View File

@ -2,8 +2,8 @@ from pathlib import Path
from urllib3.util import Url
from benchmarks.core.deluge import DelugeNode, DelugeMeta
from benchmarks.core.utils import megabytes
from benchmarks.deluge.deluge_node import DelugeNode, DelugeMeta
def test_should_seed_files(deluge_node1: DelugeNode, temp_random_file: Path, tracker: Url):

View File

@ -0,0 +1,16 @@
# from benchmarks.core.utils import megabytes
# from benchmarks.core.experiments.static_experiment import StaticDisseminationExperiment
# from benchmarks.core.experiments.tests.utils import mock_sampler
#
#
# def test_should_run_with_a_single_seeder(deluge_node1, deluge_node2, deluge_node3):
# network = [deluge_node1, deluge_node2, deluge_node3]
# experiment = StaticDisseminationExperiment(
# network=network,
# seeders=1,
# sampler=mock_sampler([1]),
# generator=RandomTempFileGenerator(size=megabytes(50))
# )
#
# ready = experiment.setup()
# ready.run()