Skip to content

Commit

Permalink
Merge pull request #676 from mplsgrant/2025-01-move-tanks-connected
Browse files Browse the repository at this point in the history
move tanks_connected to commander
  • Loading branch information
mplsgrant authored Jan 14, 2025
2 parents 80dade1 + 6059e8b commit 15cab4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
26 changes: 26 additions & 0 deletions resources/scenarios/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import signal
import sys
import tempfile
import threading
from time import sleep
from typing import Dict

from kubernetes import client, config
Expand Down Expand Up @@ -100,6 +102,30 @@ def b64_to_hex(b64, reverse=False):
else:
return base64.b64decode(b64).hex()

def wait_for_tanks_connected(self):
def tank_connected(self, tank):
while True:
peers = tank.getpeerinfo()
count = sum(
1
for peer in peers
if peer.get("connection_type") == "manual" or peer.get("addnode") is True
)
self.log.info(f"Tank {tank.tank} connected to {count}/{tank.init_peers} peers")
if count >= tank.init_peers:
break
else:
sleep(1)

conn_threads = [
threading.Thread(target=tank_connected, args=(self, tank)) for tank in self.nodes
]
for thread in conn_threads:
thread.start()

all(thread.join() is None for thread in conn_threads)
self.log.info("Network connected")

def handle_sigterm(self, signum, frame):
print("SIGTERM received, stopping...")
self.shutdown()
Expand Down
24 changes: 1 addition & 23 deletions resources/scenarios/ln_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,7 @@ def run_test(self):
# L1 P2P
##
self.log.info("Waiting for L1 p2p network connections...")

def tank_connected(self, tank):
while True:
peers = tank.getpeerinfo()
count = sum(
1
for peer in peers
if peer.get("connection_type") == "manual" or peer.get("addnode") is True
)
self.log.info(f"Tank {tank.tank} connected to {count}/{tank.init_peers} peers")
if count >= tank.init_peers:
break
else:
sleep(1)

conn_threads = [
threading.Thread(target=tank_connected, args=(self, tank)) for tank in self.nodes
]
for thread in conn_threads:
thread.start()

all(thread.join() is None for thread in conn_threads)
self.log.info("Network connected")
self.wait_for_tanks_connected()

##
# MINER
Expand Down

0 comments on commit 15cab4a

Please sign in to comment.