Skip to content

Commit

Permalink
1545 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Feb 20, 2025
1 parent 876e4c1 commit 7f3ed14
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions test/unittests/libweb3jsonrpc/run_skaled.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
import sys
import shutil
import psutil
import re
from pathlib import Path

import threading
import time

from libconsensus.sgxwallet.rapidjson.thirdparty.gtest.googlemock.test.gmock_test_utils import Subprocess





BUILD_DIR: str = "cmake-build-debug"
skaled_executable: str = "../../../" + BUILD_DIR + '/skaled/skaled'


# Set these
class Chain:

TOTAL_NODES: int

def __init__(self, _total_nodes: int):
Expand All @@ -27,7 +24,6 @@ def __init__(self, _total_nodes: int):
def __str__(self):
return f"Chain(TOTAL_NODES={self.TOTAL_NODES})"


def start(self):
print("TEST SCRIPT: Starting all nodes ")
for i in range(self.TOTAL_NODES):
Expand All @@ -40,7 +36,6 @@ def start(self):
skaled.wait_until_online(100)
test_print("All nodes online")


def stop(self):
test_print("Sending graceful signal to all nodes")

Expand All @@ -50,7 +45,7 @@ def stop(self):
test_print("Waiting all nodes to exit")
for i in range(self.TOTAL_NODES):
skaled: Skaled = skaleds[i]
skaled.terminated_if_not_exited(50)
skaled.terminated_if_not_exited(10)
test_print("Exited. Waiting for processes to stop.")
for i in range(self.TOTAL_NODES):
skaled: Skaled = skaleds[i]
Expand All @@ -61,14 +56,16 @@ def remove_created_files(self):
skaled: Skaled = skaleds[i]
skaled.cleanup()


class Skaled:
index: int
TOTAL_NODES: int
NUM_REQUIRED_PORTS: int
process: subprocess.Popen = None
stdout_thread: threading.Thread
skaled_dir : str
skaled_path : Path = None
skaled_dir: str
skaled_path: Path = None
committedBlockCount = 0

def __init__(self, _index: int, _total_nodes: int):
assert _total_nodes > 0
Expand All @@ -79,10 +76,9 @@ def __init__(self, _index: int, _total_nodes: int):
self.skaled_dir: str = f"/tmp/skaled_{self.index}_of_{self.TOTAL_NODES}"
self.skaled_path = Path(self.skaled_dir)



def check_if_online(self) -> bool:
return len(get_listening_ports_by_pid(self.process.pid)) == self.NUM_REQUIRED_PORTS
return len(
get_listening_ports_by_pid(self.process.pid)) == self.NUM_REQUIRED_PORTS and self.committedBlockCount > 1

def wait_until_online(self, _timeoutSec: int):
"""
Expand Down Expand Up @@ -127,6 +123,12 @@ def read_stdout(self):
for line in iter(self.process.stdout.readline, ''):
if line:
self.print_line(line)
if self.committedBlockCount < 4:
pattern = r'BLOCK_COMMITED'
matches = re.findall(pattern, line)
if matches:
self.committedBlockCount += 1

self.process.stdout.close()

def run(self):
Expand All @@ -135,10 +137,10 @@ def run(self):
self.skaled_path.mkdir(parents=True, exist_ok=True)
print("Directory created successfully.")

shutil.copy2(skaled_executable, self.skaled_dir + "/skaled")
shutil.copy2(skaled_executable, self.skaled_dir + "/test_skaled")

configFile: str = f"../../historicstate/configs/test_{self.index}_of_{self.TOTAL_NODES}.json"
self.process = subprocess.Popen([self.skaled_dir + "/skaled",
self.process = subprocess.Popen([self.skaled_dir + "/test_skaled",
'--config', configFile], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
text=True)

Expand All @@ -158,7 +160,6 @@ def cleanup(self):
shutil.rmtree(self.skaled_path)



skaleds: list[Skaled] = []


Expand All @@ -176,8 +177,6 @@ def test_print(_s: str):


def main():


chain = Chain(16)
chain.start()
chain.stop()
Expand Down

0 comments on commit 7f3ed14

Please sign in to comment.