From 917e1cfd9be78105ba86537fd7dcd603d8d61057 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 5 Mar 2025 00:22:40 +0000 Subject: [PATCH] test: sustained_high_rate_upload - sustained_high_rate_download - sustained_high_rate_mixed --- tests/dos_robustness/test_high_load_dos.py | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 tests/dos_robustness/test_high_load_dos.py diff --git a/tests/dos_robustness/test_high_load_dos.py b/tests/dos_robustness/test_high_load_dos.py new file mode 100644 index 0000000..ab178ac --- /dev/null +++ b/tests/dos_robustness/test_high_load_dos.py @@ -0,0 +1,112 @@ +import time + +import pytest + +from src.libs.common import to_app_id, to_index, delay +from src.steps.da import StepsDataAvailability, logger +from src.test_data import DATA_TO_DISPERSE + + +class TestHighLoadDos(StepsDataAvailability): + main_nodes = [] + + @pytest.mark.usefixtures("setup_2_node_cluster") + def test_sustained_high_rate_upload(self): + timeout = 60 + start_time = time.time() + successful_dispersals = 0 + unsuccessful_dispersals = 0 + + while True: + if time.time() - start_time > timeout: + break + + delay(0.01) + try: + response = self.disperse_data(DATA_TO_DISPERSE[7], to_app_id(1), to_index(0), timeout_duration=0) + if response.status_code == 200: + successful_dispersals += 1 + else: + unsuccessful_dispersals += 1 + except Exception: + unsuccessful_dispersals += 1 + + assert successful_dispersals > 0, "No successful dispersals" + + failure_ratio = unsuccessful_dispersals / successful_dispersals + logger.info(f"Unsuccessful dispersals ratio: {failure_ratio}") + + assert failure_ratio < 0.20, f"Dispersal failure ratio {failure_ratio} too high" + + @pytest.mark.usefixtures("setup_2_node_cluster") + def test_sustained_high_rate_download(self): + timeout = 60 + successful_downloads = 0 + unsuccessful_downloads = 0 + + try: + self.disperse_data(DATA_TO_DISPERSE[7], to_app_id(1), to_index(0)) + except Exception as ex: + raise Exception(f"Initial dispersal was not successful with error {ex}") + + delay(5) + start_time = time.time() + + while True: + if time.time() - start_time > timeout: + break + + delay(0.01) + try: + self.get_data_range(self.node2, to_app_id(1), to_index(0), to_index(5), timeout_duration=0) + successful_downloads += 1 + except Exception: + unsuccessful_downloads += 1 + + assert successful_downloads > 0, "No successful data downloads" + + failure_ratio = unsuccessful_downloads / successful_downloads + logger.info(f"Unsuccessful download ratio: {failure_ratio}") + + assert failure_ratio < 0.20, f"Data download failure ratio {failure_ratio} too high" + + @pytest.mark.usefixtures("setup_2_node_cluster") + def test_sustained_high_rate_mixed(self): + timeout = 60 + start_time = time.time() + successful_dispersals = 0 + unsuccessful_dispersals = 0 + successful_downloads = 0 + unsuccessful_downloads = 0 + + while True: + if time.time() - start_time > timeout: + break + + delay(0.01) + try: + response = self.disperse_data(DATA_TO_DISPERSE[6], to_app_id(1), to_index(0), timeout_duration=0) + if response.status_code == 200: + successful_dispersals += 1 + else: + unsuccessful_dispersals += 1 + except Exception: + unsuccessful_dispersals += 1 + + try: + self.get_data_range(self.node2, to_app_id(1), to_index(0), to_index(5), timeout_duration=0) + successful_downloads += 1 + except Exception: + unsuccessful_downloads += 1 + + assert successful_dispersals > 0, "No successful dispersals" + assert successful_downloads > 0, "No successful downloads" + + failure_ratio_w = unsuccessful_dispersals / successful_dispersals + failure_ratio_r = unsuccessful_downloads / successful_downloads + + logger.info(f"Unsuccessful dispersals ratio: {failure_ratio_w}") + logger.info(f"Unsuccessful download ratio: {failure_ratio_r}") + + assert failure_ratio_w < 0.20, f"Dispersal failure ratio {failure_ratio_w} too high" + assert failure_ratio_r < 0.20, f"Data download failure ratio {failure_ratio_r} too high"