test: consumed bandwidth random data dispersal

This commit is contained in:
Roman 2025-02-28 01:18:14 +00:00
parent d087db7285
commit ab9825ca0a
No known key found for this signature in database
GPG Key ID: BB3828275C58EFF1
4 changed files with 50 additions and 7 deletions

View File

@ -7,7 +7,7 @@ security_param: 10
active_slot_coeff: 0.9
# DaConfig related parameters
subnetwork_size: 1024
subnetwork_size: 2
dispersal_factor: 2
num_samples: 1
num_subnets: 2

View File

@ -38,3 +38,8 @@ def to_app_id(n: int) -> list:
if n < 0:
raise ValueError("Input must be an unsigned integer (non-negative)")
return list(n.to_bytes(32, byteorder="big"))
def generate_random_bytes(n_max=31):
random_n = random.randint(1, n_max)
return os.urandom(random_n)

View File

@ -46,9 +46,13 @@ def remove_padding(padded_bytes):
return padded_bytes[:-padding_len]
def prepare_dispersal_request(data, app_id, index):
data_bytes = data.encode("utf-8")
padded_bytes = add_padding(list(data_bytes))
def prepare_dispersal_request(data, app_id, index, with_utf8_padding=True):
if with_utf8_padding:
data_bytes = data.encode("utf-8")
padded_bytes = add_padding(list(data_bytes))
else:
padded_bytes = list(data)
dispersal_data = {"data": padded_bytes, "metadata": {"app_id": app_id, "index": index}}
return dispersal_data
@ -76,9 +80,9 @@ class StepsDataAvailability(StepsCommon):
@allure.step
@retry(stop=stop_after_delay(65), wait=wait_fixed(1), reraise=True)
def disperse_data(self, data, app_id, index):
def disperse_data(self, data, app_id, index, with_utf8_padding=True):
response = []
request = prepare_dispersal_request(data, app_id, index)
request = prepare_dispersal_request(data, app_id, index, with_utf8_padding)
executor = self.find_executor_node()
try:
response = executor.send_dispersal_request(request)

View File

@ -1,7 +1,7 @@
import pytest
import psutil
from src.libs.common import delay, to_app_id, to_index
from src.libs.common import delay, to_app_id, to_index, generate_random_bytes
from src.libs.custom_logger import get_custom_logger
from src.steps.da import StepsDataAvailability
from src.test_data import DATA_TO_DISPERSE
@ -42,3 +42,37 @@ class TestNetworkingPrivacy(StepsDataAvailability):
overhead = (consumed - data_sent) / data_sent
assert overhead < 400, "Dispersal overhead is too high"
@pytest.mark.usefixtures("setup_2_node_cluster")
def test_consumed_bandwidth_random_data_dispersal(self):
delay(5)
net_io = psutil.net_io_counters()
prev_total = net_io.bytes_sent + net_io.bytes_recv
data_to_disperse = generate_random_bytes()
logger.debug(f"Using random data to disperse: {list(data_to_disperse)}")
successful_dispersals = 0
for i in range(20):
try:
self.disperse_data(data_to_disperse, to_app_id(1), to_index(0), with_utf8_padding=False)
successful_dispersals += 1
except Exception as ex:
logger.warning(f"Dispersal #{i} was not successful with error {ex}")
if successful_dispersals == 10:
break
delay(0.1)
net_io = psutil.net_io_counters()
curr_total = net_io.bytes_sent + net_io.bytes_recv
consumed = curr_total - prev_total
assert successful_dispersals == 10, "Unable to finish 10 successful dispersals"
data_sent = 2 * successful_dispersals * len(data_to_disperse)
overhead = (consumed - data_sent) / data_sent
assert overhead < 400, "Dispersal overhead is too high"