fix: update related test and variables

This commit is contained in:
Roman 2025-03-10 05:57:22 +00:00
parent d85c19269a
commit 5305bc9102
No known key found for this signature in database
GPG Key ID: BB3828275C58EFF1
10 changed files with 44 additions and 47 deletions

View File

@ -9,11 +9,7 @@ logger = get_custom_logger(__name__)
class BaseClient:
def make_request(self, method, url, headers=None, data=None):
self.log_request_as_curl(method, url, headers, data)
try:
response = requests.request(method.upper(), url, headers=headers, data=data, timeout=API_REQUEST_TIMEOUT)
except Exception as ex:
logger.error(f"HERE An error occurred: {ex}. ")
response = requests.request(method.upper(), url, headers=headers, data=data, timeout=API_REQUEST_TIMEOUT)
try:
response.raise_for_status()
except requests.HTTPError as http_err:

View File

@ -54,8 +54,8 @@ def alter_get_range_query(query):
class INVALID_REST(REST):
def __init__(self, port, host="127.0.0.1"):
super().__init__(port, host)
def __init__(self, rest_port):
super().__init__(rest_port)
def send_dispersal_request(self, data):
data = alter_dispersal_data(data)

View File

@ -6,17 +6,16 @@ logger = get_custom_logger(__name__)
class REST(BaseClient):
def __init__(self, port, host="127.0.0.1"):
self._rest_port = port
self._rest_host = host
def __init__(self, rest_port):
self._rest_port = rest_port
def rest_call(self, method, endpoint, payload=None):
url = f"http://{self._rest_host}:{self._rest_port}/{endpoint}"
url = f"http://localhost:{self._rest_port}/{endpoint}"
headers = {"Content-Type": "application/json", "Connection": "close"}
return self.make_request(method, url, headers=headers, data=payload)
def rest_call_text(self, method, endpoint, payload=None):
url = f"http://{self._rest_host}:{self._rest_port}/{endpoint}"
url = f"http://localhost:{self._rest_port}/{endpoint}"
headers = {"accept": "text/plain", "Connection": "close"}
return self.make_request(method, url, headers=headers, data=payload)

View File

@ -37,7 +37,6 @@ class NomosCli:
self._docker_manager = DockerManager(self._image_name)
self._container_name = container_name
self._container = None
self._api = None
cwd = os.getcwd()
self._volumes = [cwd + "/" + volume for volume in self._volumes]
@ -48,7 +47,6 @@ class NomosCli:
self._port_map = {}
cmd = [NOMOS_CLI, self._command]
for flag in nomos_cli[self._command]["flags"]:
for f, indexes in flag.items():
cmd.append(f)
@ -76,7 +74,7 @@ class NomosCli:
decode_only = kwargs.get("decode_only", False)
return self.reconstruct(decode_only=decode_only)
case _:
return None
return
def reconstruct(self, decode_only=False):
keywords = ["Reconstructed data"]
@ -105,9 +103,6 @@ class NomosCli:
return result
def set_rest_api(self, host, port):
self._api = REST(port, host)
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def stop(self):
self._container = stop(self._container)

View File

@ -76,11 +76,11 @@ class ProxyClient:
DS.client_nodes.append(self)
def set_rest_api(self, host, port):
self._api = REST(port, host)
def set_rest_api(self):
self._api = REST(self._tcp_port)
def set_invalid_rest_api(self, host, port):
self._api = INVALID_REST(port, host)
def set_invalid_rest_api(self):
self._api = INVALID_REST(self._tcp_port)
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def stop(self):

View File

@ -15,20 +15,21 @@ def get_env_var(var_name, default=None):
# Configuration constants. Need to be upercase to appear in reports
DEFAULT_NOMOS_IMAGE = "ghcr.io/logos-co/nomos-node:testnet"
NOMOS_IMAGE = get_env_var("NOMOS_IMAGE", DEFAULT_NOMOS_IMAGE)
DEFAULT_PROXY_IMAGE = "bitnami/configurable-http-proxy:latest"
HTTP_PROXY_IMAGE = get_env_var("HTTP_PROXY_IMAGE", DEFAULT_PROXY_IMAGE)
NOMOS = "nomos"
NOMOS_EXECUTOR = "nomos_executor"
CFGSYNC = "cfgsync"
DEFAULT_IMAGE = "ghcr.io/logos-co/nomos-node:testnet"
NOMOS_IMAGE = get_env_var("NOMOS_IMAGE", DEFAULT_IMAGE)
HTTP_PROXY_IMAGE = get_env_var("HTTP_PROXY_IMAGE", "bitnami/configurable-http-proxy:latest")
NODE_1 = get_env_var("NODE_1", NOMOS)
NODE_2 = get_env_var("NODE_2", NOMOS_EXECUTOR)
NODE_3 = get_env_var("NODE_3", CFGSYNC)
NOMOS_CLI = "/usr/bin/nomos-client"
NOMOS_CLI = "/usr/bin/nomos-cli"
ADDITIONAL_NODES = get_env_var("ADDITIONAL_NODES", f"{NOMOS},{NOMOS}")
# more nodes need to follow the NODE_X pattern

View File

@ -1,10 +1,9 @@
import inspect
import os
import shutil
import pytest
from src.client.nomos_cli import NomosCli
from src.client.proxy_client import ProxyClient
from src.env_vars import CFGSYNC, NOMOS, NOMOS_EXECUTOR
from src.libs.common import delay
from src.libs.custom_logger import get_custom_logger
@ -91,15 +90,21 @@ class StepsCommon:
delay(5)
@pytest.fixture(scope="function")
def setup_client_nodes(self, request):
def setup_proxy_clients(self, request):
logger.debug(f"Running fixture setup: {inspect.currentframe().f_code.co_name}")
assert len(self.main_nodes) == 3, "There should be two Nomos nodes running already"
if hasattr(request, "param"):
num_clients = request.param
else:
num_clients = 5
num_clients = 10
assert num_clients % 2 == 0, "num_clients must be an even number"
# Every even proxy client for get-range, every odd for dispersal
for i in range(num_clients):
cli_node = NomosCli(command="client_node")
cli_node.run()
self.client_nodes.append(cli_node)
proxy_client = ProxyClient()
default_target = [f"http://{self.main_nodes[1 + i % 2].name()}:18080"]
proxy_client.run(input_values=default_target)
self.client_nodes.append(proxy_client)

View File

@ -57,9 +57,9 @@ class StepsDataAvailability(StepsCommon):
response = executor.send_dispersal_request(request)
else:
if send_invalid:
client_node.set_invalid_rest_api(executor.name(), executor.api_port_internal())
client_node.set_invalid_rest_api()
else:
client_node.set_rest_api(executor.name(), executor.api_port_internal())
client_node.set_rest_api()
response = client_node.send_dispersal_request(request)
except Exception as ex:
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
@ -82,9 +82,9 @@ class StepsDataAvailability(StepsCommon):
response = node.send_get_data_range_request(query)
else:
if send_invalid:
client_node.set_invalid_rest_api(node.name(), node.api_port_internal())
client_node.set_invalid_rest_api()
else:
client_node.set_rest_api(node.name(), node.api_port_internal())
client_node.set_rest_api()
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)

View File

@ -3,7 +3,7 @@ import random
import pytest
from src.cli.nomos_cli import NomosCli
from src.client.nomos_cli import NomosCli
from src.libs.common import delay, to_app_id, to_index
from src.libs.custom_logger import get_custom_logger
from src.steps.da import StepsDataAvailability

View File

@ -113,7 +113,7 @@ 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")
@pytest.mark.usefixtures("setup_2_node_cluster", "setup_proxy_clients")
def test_sustained_high_rate_multiple_clients(self):
timeout = 10
start_time = time.time()
@ -126,7 +126,7 @@ class TestHighLoadDos(StepsDataAvailability):
if time.time() - start_time > timeout:
break
dispersal_cl, download_cl = random.choice(self.client_nodes), random.choice(self.client_nodes)
dispersal_cl, download_cl = random.choice(self.client_nodes[1::2]), random.choice(self.client_nodes[::2])
delay(0.01)
try:
@ -156,7 +156,8 @@ 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")
@pytest.mark.timeout(3600)
@pytest.mark.usefixtures("setup_2_node_cluster", "setup_proxy_clients")
def test_sustained_high_rate_with_invalid_requests(self):
timeout = 10
start_time = time.time()
@ -169,10 +170,8 @@ class TestHighLoadDos(StepsDataAvailability):
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])
dispersal_cl, download_cl = random.choice(self.client_nodes[1::2]), random.choice(self.client_nodes[::2])
invalid = random.choice([False])
try:
response = self.disperse_data(
@ -195,6 +194,8 @@ class TestHighLoadDos(StepsDataAvailability):
if not invalid:
unsuccessful_downloads += 1
delay(10)
assert successful_dispersals > 0, "No successful dispersals"
assert successful_downloads > 0, "No successful downloads"