mirror of
https://github.com/logos-blockchain/logos-blockchain-e2e-tests.git
synced 2026-01-02 13:13:08 +00:00
test: with invalid requests
This commit is contained in:
parent
73acf52329
commit
dd1134dcc4
@ -1,5 +1,4 @@
|
||||
import allure
|
||||
from requests.packages import target
|
||||
from tenacity import retry, stop_after_delay, wait_fixed
|
||||
|
||||
from src.env_vars import NOMOS_EXECUTOR
|
||||
@ -46,7 +45,7 @@ class StepsDataAvailability(StepsCommon):
|
||||
return executor
|
||||
|
||||
@allure.step
|
||||
def disperse_data(self, data, app_id, index, client_node=None, timeout_duration=65, utf8=True, padding=True):
|
||||
def disperse_data(self, data, app_id, index, client_node=None, timeout_duration=65, utf8=True, padding=True, send_invalid=False):
|
||||
@retry(stop=stop_after_delay(timeout_duration), wait=wait_fixed(0.1), reraise=True)
|
||||
def disperse(my_self=self):
|
||||
response = []
|
||||
@ -57,7 +56,10 @@ class StepsDataAvailability(StepsCommon):
|
||||
if client_node is None:
|
||||
response = executor.send_dispersal_request(request)
|
||||
else:
|
||||
client_node.set_rest_api(executor.name(), executor.api_port_internal())
|
||||
if send_invalid:
|
||||
client_node.set_invalid_rest_api(executor.name(), executor.api_port_internal())
|
||||
else:
|
||||
client_node.set_rest_api(executor.name(), executor.api_port_internal())
|
||||
response = client_node.send_dispersal_request(request)
|
||||
except Exception as ex:
|
||||
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
|
||||
@ -70,7 +72,7 @@ class StepsDataAvailability(StepsCommon):
|
||||
return disperse()
|
||||
|
||||
@allure.step
|
||||
def get_data_range(self, node, app_id, start, end, client_node=None, timeout_duration=45):
|
||||
def get_data_range(self, node, app_id, start, end, client_node=None, timeout_duration=45, send_invalid=False):
|
||||
@retry(stop=stop_after_delay(timeout_duration), wait=wait_fixed(0.1), reraise=True)
|
||||
def get_range():
|
||||
response = []
|
||||
@ -79,7 +81,10 @@ class StepsDataAvailability(StepsCommon):
|
||||
if client_node is None:
|
||||
response = node.send_get_data_range_request(query)
|
||||
else:
|
||||
client_node.set_rest_api(node.name(), node.api_port_internal())
|
||||
if send_invalid:
|
||||
client_node.set_invalid_rest_api(node.name(), node.api_port_internal())
|
||||
else:
|
||||
client_node.set_rest_api(node.name(), node.api_port_internal())
|
||||
response = client_node.send_get_data_range_request(query)
|
||||
except Exception as ex:
|
||||
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
|
||||
|
||||
@ -155,3 +155,55 @@ class TestHighLoadDos(StepsDataAvailability):
|
||||
|
||||
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"
|
||||
|
||||
@pytest.mark.usefixtures("setup_2_node_cluster", "setup_client_nodes")
|
||||
def test_sustained_high_rate_with_invalid_requests(self):
|
||||
timeout = 10
|
||||
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
|
||||
|
||||
dispersal_cl, download_cl = random.choice(self.client_nodes), random.choice(self.client_nodes)
|
||||
|
||||
delay(0.01)
|
||||
invalid = random.choice([True, False])
|
||||
|
||||
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
|
||||
)
|
||||
if response.status_code == 200:
|
||||
successful_dispersals += 1
|
||||
elif not invalid:
|
||||
unsuccessful_dispersals += 1
|
||||
except Exception:
|
||||
if not invalid:
|
||||
unsuccessful_dispersals += 1
|
||||
|
||||
try:
|
||||
invalid = random.choice([True, False])
|
||||
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
|
||||
|
||||
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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user