From f66a5bd394525eb3b4d4092f5f2c9934e6fc1b73 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 5 Mar 2025 11:18:03 +0000 Subject: [PATCH] fix: reduce fixture repetition - improve comment --- src/libs/common.py | 2 +- tests/dos_robustness/test_spam_protection.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libs/common.py b/src/libs/common.py index 4d6184d..8047f9c 100644 --- a/src/libs/common.py +++ b/src/libs/common.py @@ -42,7 +42,7 @@ def to_app_id(n: int) -> list: def random_divide_k(n, k): if n < k: - raise ValueError("n must be at least k to split into k parts.") + raise ValueError(f"n={n} must be at least k={k} to split into {k} parts") cuts = sorted(random.sample(range(1, n), k - 1)) parts = [cuts[0]] + [cuts[i] - cuts[i - 1] for i in range(1, len(cuts))] + [n - cuts[-1]] return parts diff --git a/tests/dos_robustness/test_spam_protection.py b/tests/dos_robustness/test_spam_protection.py index 68e663a..0dec50d 100644 --- a/tests/dos_robustness/test_spam_protection.py +++ b/tests/dos_robustness/test_spam_protection.py @@ -9,10 +9,10 @@ from src.test_data import DATA_TO_DISPERSE logger = get_custom_logger(__name__) +@pytest.mark.usefixtures("setup_2_node_cluster") class TestSpamProtection(StepsDataAvailability): main_nodes = [] - @pytest.mark.usefixtures("setup_2_node_cluster") def test_spam_protection_valid_uploads(self): num_samples = len(DATA_TO_DISPERSE) missing_dispersals = num_samples @@ -28,7 +28,6 @@ class TestSpamProtection(StepsDataAvailability): assert missing_dispersals == 0, f"{missing_dispersals} dispersals were not successful" - @pytest.mark.usefixtures("setup_2_node_cluster") def test_spam_protection_single_burst(self): rate_limit = 1000 spam_per_burst = rate_limit + 10 @@ -45,7 +44,6 @@ class TestSpamProtection(StepsDataAvailability): assert successful_dispersals <= rate_limit, "All consecutive dispersals were successful without any constraint" - @pytest.mark.usefixtures("setup_2_node_cluster") def test_spam_protection_random_bytes_single_burst(self): rate_limit = 1000 spam_per_burst = rate_limit + 10 @@ -66,7 +64,6 @@ class TestSpamProtection(StepsDataAvailability): assert successful_dispersals <= rate_limit, "All consecutive dispersals were successful without any constraint" - @pytest.mark.usefixtures("setup_2_node_cluster") def test_spam_protection_multiple_bursts(self): time_interval = 60 rate_limit = 1000