Skip to content

Commit 14c50c3

Browse files
committed
improve test
Sleep a bit to allow simln to process
1 parent 0cb1163 commit 14c50c3

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

resources/plugins/simln/simln.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from time import sleep
77

88
from warnet.hooks import _get_plugin_directory as get_plugin_directory
9-
from warnet.k8s import get_pods_with_label
9+
from warnet.k8s import get_pods_with_label, wait_for_pod
1010
from warnet.process import run_command
1111
from warnet.status import _get_tank_status as network_status
1212

@@ -43,12 +43,15 @@ def run_simln():
4343
log.info("done waiting")
4444
pod_name = prepare_and_launch_activity()
4545
log.info(pod_name)
46+
wait_for_pod(pod_name, 60)
4647

4748

4849
def prepare_and_launch_activity() -> str:
4950
pods = get_pods_with_label(lightning_selector)
50-
pod_a = pods[0].metadata.name
51-
pod_b = pods[1].metadata.name
51+
pod_a = pods[1].metadata.name
52+
pod_b = pods[2].metadata.name
53+
log.info(f"pod_a: {pod_a}")
54+
log.info(f"pod_b: {pod_b}")
5255
sample_activity = [
5356
{"source": pod_a, "destination": pod_b, "interval_secs": 1, "amount_msat": 2000}
5457
]
@@ -65,7 +68,7 @@ def launch_activity(activity: list[dict]) -> str:
6568
command = f"helm upgrade --install simln-{random_digits} {plugin_dir}/simln/charts/simln"
6669
log.info(f"generate activity: {command}")
6770
run_command(command)
68-
return f"pod/simln-simln-{random_digits}"
71+
return f"simln-simln-{random_digits}"
6972

7073

7174
def init_network():

src/warnet/k8s.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ def download(pod_name: str, namespace: str, source_path: Path, destination_path:
569569

570570
v1 = get_static_client()
571571

572-
os.makedirs(destination_path, exist_ok=True)
573572
target_folder = destination_path / source_path.stem
574573
os.makedirs(target_folder, exist_ok=True)
575574

test/simln_test.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
2+
import json
33
import os
44
from pathlib import Path
55
from subprocess import run
@@ -8,7 +8,10 @@
88
import pexpect
99
from test_base import TestBase
1010

11-
from warnet.k8s import download, get_pods_with_label
11+
from warnet.k8s import download, get_pods_with_label, pod_log, wait_for_pod
12+
from warnet.process import run_command
13+
14+
lightning_selector = "mission=lightning"
1215

1316

1417
class LNTest(TestBase):
@@ -42,8 +45,15 @@ def run_plugin(self):
4245

4346
def copy_results(self) -> bool:
4447
self.log.info("Copying results")
45-
sleep(20)
4648
pod = get_pods_with_label("mission=plugin")[0]
49+
self.wait_for_gossip_sync(2)
50+
wait_for_pod(pod.metadata.name, 60)
51+
sleep(20)
52+
53+
log_resp = pod_log(pod.metadata.name, "simln")
54+
self.log.info(log_resp.data.decode("utf-8"))
55+
self.log.info("Sleep to process results")
56+
sleep(60)
4757

4858
download(pod.metadata.name, pod.metadata.namespace, Path("/working/results"), Path("."))
4959

@@ -57,6 +67,20 @@ def copy_results(self) -> bool:
5767
return True
5868
return False
5969

70+
def wait_for_gossip_sync(self, expected: int):
71+
self.log.info(f"Waiting for sync (expecting {expected})...")
72+
current = 0
73+
while current < expected:
74+
current = 0
75+
pods = get_pods_with_label(lightning_selector)
76+
for v1_pod in pods:
77+
node = v1_pod.metadata.name
78+
chs = json.loads(run_command(f"warnet ln rpc {node} describegraph"))["edges"]
79+
self.log.info(f"{node}: {len(chs)} channels")
80+
current += len(chs)
81+
sleep(1)
82+
self.log.info("Synced")
83+
6084

6185
if __name__ == "__main__":
6286
test = LNTest()

0 commit comments

Comments
 (0)