status-cli-tests/tests/test_leave_community.py

55 lines
2.1 KiB
Python
Raw Normal View History

2024-06-21 15:38:37 +00:00
import pytest
from src.libs.common import delay
from src.steps.common import StepsCommon
from datetime import datetime
2024-07-10 13:59:42 +00:00
@pytest.mark.usefixtures("start_1_node")
2024-07-01 13:47:37 +00:00
class TestLeaveCommunity(StepsCommon):
2024-06-21 15:38:37 +00:00
def test_leave_community_baseline(self):
try:
2024-07-10 13:59:42 +00:00
self.community_nodes
2024-06-21 15:38:37 +00:00
except:
2024-07-10 13:59:42 +00:00
self.setup_community_nodes()
2024-06-21 15:38:37 +00:00
self.join_created_communities()
2024-07-01 14:31:07 +00:00
delay(10)
2024-06-21 15:38:37 +00:00
failed_community_leave = []
2024-07-10 13:59:42 +00:00
for community_id, _, _, initial_members in self.community_join_requests:
2024-06-21 15:38:37 +00:00
leave_ts = datetime.now().strftime("%H:%M:%S")
2024-07-10 13:59:42 +00:00
response_accept_to_join = self.first_node.leave_community(community_id)
2024-06-21 15:38:37 +00:00
try:
target_community = [
existing_community
for existing_community in response_accept_to_join["result"]["communities"]
if existing_community["id"] == community_id
][0]
2024-08-21 10:09:18 +00:00
assert target_community["joined"] == False
2024-06-21 15:38:37 +00:00
except Exception as ex:
failed_community_leave.append((leave_ts, community_id, str(ex)))
if failed_community_leave:
formatted_missing_requests = [f"Leave Timestamp: {lts}, Community ID: {cid}, Error: {er}" for lts, cid, er in failed_community_leave]
2024-07-10 13:59:42 +00:00
raise AssertionError(
f"{len(failed_community_leave)} community joins out of {len(self.community_nodes)}: " + "\n".join(formatted_missing_requests)
)
2024-06-21 15:38:37 +00:00
def test_leave_community_with_latency(self):
2024-07-10 13:59:42 +00:00
self.setup_community_nodes()
2024-06-21 15:38:37 +00:00
self.join_created_communities()
with self.add_latency():
self.test_leave_community_baseline()
def test_leave_community_with_packet_loss(self):
2024-07-10 13:59:42 +00:00
self.setup_community_nodes()
2024-06-21 15:38:37 +00:00
self.join_created_communities()
with self.add_packet_loss():
self.test_leave_community_baseline()
2024-07-01 14:03:09 +00:00
def test_leave_community_with_low_bandwith(self):
2024-07-10 13:59:42 +00:00
self.setup_community_nodes()
2024-06-21 15:38:37 +00:00
self.join_created_communities()
with self.add_low_bandwith():
self.test_leave_community_baseline()