2025-03-06 02:14:41 +00:00
|
|
|
import random
|
2025-03-05 00:22:40 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2025-04-24 16:03:18 +08:00
|
|
|
from src.env_vars import CONSENSUS_SLOT_TIME
|
2025-03-05 00:22:40 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2025-03-12 00:37:10 +00:00
|
|
|
@pytest.mark.usefixtures("setup_2_node_cluster")
|
2025-03-05 00:22:40 +00:00
|
|
|
class TestHighLoadDos(StepsDataAvailability):
|
|
|
|
|
main_nodes = []
|
2025-03-05 03:37:11 +00:00
|
|
|
client_nodes = []
|
2025-03-05 00:22:40 +00:00
|
|
|
|
|
|
|
|
def test_sustained_high_rate_upload(self):
|
|
|
|
|
timeout = 60
|
|
|
|
|
start_time = time.time()
|
|
|
|
|
successful_dispersals = 0
|
|
|
|
|
unsuccessful_dispersals = 0
|
|
|
|
|
|
2025-03-12 00:37:10 +00:00
|
|
|
while time.time() - start_time < timeout:
|
2025-03-05 00:22:40 +00:00
|
|
|
|
|
|
|
|
delay(0.01)
|
|
|
|
|
try:
|
|
|
|
|
response = self.disperse_data(DATA_TO_DISPERSE[7], to_app_id(1), to_index(0), timeout_duration=0)
|
2025-03-12 03:07:32 +00:00
|
|
|
assert response.status_code == 200, f"Dispersal failed with status code {response.status_code}"
|
|
|
|
|
successful_dispersals += 1
|
|
|
|
|
except AssertionError:
|
2025-03-05 00:22:40 +00:00
|
|
|
unsuccessful_dispersals += 1
|
|
|
|
|
|
2025-03-12 03:07:32 +00:00
|
|
|
assert successful_dispersals > 0, "No successful dispersal"
|
2025-03-05 00:22:40 +00:00
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
def test_sustained_high_rate_download(self):
|
|
|
|
|
timeout = 60
|
|
|
|
|
successful_downloads = 0
|
|
|
|
|
unsuccessful_downloads = 0
|
|
|
|
|
|
2025-03-12 03:07:32 +00:00
|
|
|
response = self.disperse_data(DATA_TO_DISPERSE[7], to_app_id(1), to_index(0))
|
|
|
|
|
assert response.status_code == 200, "Initial dispersal was not successful"
|
2025-03-05 00:22:40 +00:00
|
|
|
|
2025-04-24 16:03:18 +08:00
|
|
|
delay(CONSENSUS_SLOT_TIME)
|
2025-03-05 00:22:40 +00:00
|
|
|
start_time = time.time()
|
|
|
|
|
|
2025-03-12 00:37:10 +00:00
|
|
|
while time.time() - start_time < timeout:
|
2025-03-05 00:22:40 +00:00
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2025-03-12 00:37:10 +00:00
|
|
|
while time.time() - start_time < timeout:
|
2025-03-05 03:37:11 +00:00
|
|
|
|
|
|
|
|
delay(0.01)
|
|
|
|
|
try:
|
|
|
|
|
response = self.disperse_data(DATA_TO_DISPERSE[6], to_app_id(1), to_index(0), timeout_duration=0)
|
2025-03-12 03:07:32 +00:00
|
|
|
assert response.status_code == 200, f"Dispersal failed with status code {response.status_code}"
|
|
|
|
|
successful_dispersals += 1
|
|
|
|
|
except AssertionError:
|
2025-03-05 03:37:11 +00:00
|
|
|
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
|
|
|
|
|
|
2025-03-12 03:07:32 +00:00
|
|
|
assert successful_dispersals > 0, "No successful dispersal"
|
|
|
|
|
assert successful_downloads > 0, "No successful download"
|
2025-03-05 03:37:11 +00:00
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
2025-03-10 05:57:22 +00:00
|
|
|
@pytest.mark.usefixtures("setup_2_node_cluster", "setup_proxy_clients")
|
2025-03-05 03:37:11 +00:00
|
|
|
def test_sustained_high_rate_multiple_clients(self):
|
2025-03-12 03:09:35 +00:00
|
|
|
timeout = 60
|
2025-03-05 03:37:11 +00:00
|
|
|
start_time = time.time()
|
|
|
|
|
successful_dispersals = 0
|
|
|
|
|
unsuccessful_dispersals = 0
|
|
|
|
|
successful_downloads = 0
|
|
|
|
|
unsuccessful_downloads = 0
|
|
|
|
|
|
2025-03-12 00:37:10 +00:00
|
|
|
while time.time() - start_time < timeout:
|
2025-03-05 00:22:40 +00:00
|
|
|
|
2025-03-10 05:57:22 +00:00
|
|
|
dispersal_cl, download_cl = random.choice(self.client_nodes[1::2]), random.choice(self.client_nodes[::2])
|
2025-03-06 02:14:41 +00:00
|
|
|
|
2025-03-05 00:22:40 +00:00
|
|
|
delay(0.01)
|
|
|
|
|
try:
|
2025-03-06 02:14:41 +00:00
|
|
|
response = self.disperse_data(DATA_TO_DISPERSE[6], to_app_id(1), to_index(0), client_node=dispersal_cl, timeout_duration=0)
|
2025-03-12 03:07:32 +00:00
|
|
|
assert response.status_code == 200, f"Dispersal failed with status code {response.status_code}"
|
|
|
|
|
successful_dispersals += 1
|
|
|
|
|
except AssertionError:
|
2025-03-05 00:22:40 +00:00
|
|
|
unsuccessful_dispersals += 1
|
|
|
|
|
|
2025-03-06 02:14:41 +00:00
|
|
|
try:
|
|
|
|
|
self.get_data_range(self.node2, to_app_id(1), to_index(0), to_index(5), client_node=download_cl, timeout_duration=0)
|
|
|
|
|
successful_downloads += 1
|
|
|
|
|
except Exception:
|
|
|
|
|
unsuccessful_downloads += 1
|
2025-03-05 00:22:40 +00:00
|
|
|
|
2025-03-12 03:07:32 +00:00
|
|
|
assert successful_dispersals > 0, "No successful dispersal"
|
|
|
|
|
assert successful_downloads > 0, "No successful download"
|
2025-03-05 00:22:40 +00:00
|
|
|
|
|
|
|
|
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"
|
2025-03-07 03:33:34 +00:00
|
|
|
|
2025-03-10 05:57:22 +00:00
|
|
|
@pytest.mark.usefixtures("setup_2_node_cluster", "setup_proxy_clients")
|
2025-03-07 03:33:34 +00:00
|
|
|
def test_sustained_high_rate_with_invalid_requests(self):
|
2025-03-10 23:59:21 +00:00
|
|
|
timeout = 60
|
2025-03-07 03:33:34 +00:00
|
|
|
start_time = time.time()
|
|
|
|
|
successful_dispersals = 0
|
|
|
|
|
unsuccessful_dispersals = 0
|
|
|
|
|
successful_downloads = 0
|
|
|
|
|
unsuccessful_downloads = 0
|
|
|
|
|
|
2025-03-12 00:37:10 +00:00
|
|
|
while time.time() - start_time < timeout:
|
2025-03-07 03:33:34 +00:00
|
|
|
|
2025-03-10 05:57:22 +00:00
|
|
|
dispersal_cl, download_cl = random.choice(self.client_nodes[1::2]), random.choice(self.client_nodes[::2])
|
2025-03-11 23:39:50 +00:00
|
|
|
invalid = random.choice([False, True])
|
2025-03-07 03:33:34 +00:00
|
|
|
|
2025-03-11 03:17:36 +00:00
|
|
|
delay(0.01)
|
2025-03-07 03:33:34 +00:00
|
|
|
try:
|
|
|
|
|
response = self.disperse_data(
|
|
|
|
|
DATA_TO_DISPERSE[6], to_app_id(1), to_index(0), client_node=dispersal_cl, timeout_duration=0, send_invalid=invalid
|
|
|
|
|
)
|
2025-04-29 15:35:57 +08:00
|
|
|
assert response.status_code == 200, f"Dispersal failed with unexpected status code {response.status_code}"
|
2025-03-12 03:07:32 +00:00
|
|
|
successful_dispersals += 1
|
2025-04-29 15:35:57 +08:00
|
|
|
except Exception as ex:
|
|
|
|
|
assert "422" in str(ex), f"Unexpected error: {ex}"
|
2025-03-07 03:33:34 +00:00
|
|
|
if not invalid:
|
|
|
|
|
unsuccessful_dispersals += 1
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.get_data_range(
|
|
|
|
|
self.node2, to_app_id(1), to_index(0), to_index(5), client_node=download_cl, timeout_duration=0, send_invalid=invalid
|
|
|
|
|
)
|
|
|
|
|
successful_downloads += 1
|
|
|
|
|
except Exception:
|
|
|
|
|
if not invalid:
|
|
|
|
|
unsuccessful_downloads += 1
|
|
|
|
|
|
2025-03-12 03:07:32 +00:00
|
|
|
assert successful_dispersals > 0, "No successful dispersal"
|
|
|
|
|
assert successful_downloads > 0, "No successful download"
|
2025-03-07 03:33:34 +00:00
|
|
|
|
|
|
|
|
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"
|