Skip to content

Commit a9498f9

Browse files
committed
allow wait_for_predicate to return result
Do this in order to easily get results during testing
1 parent 10b8fb1 commit a9498f9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

test/ln_test.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ast
33
import json
44
import os
5+
from functools import partial
56
from pathlib import Path
67
from typing import Optional
78

@@ -42,10 +43,22 @@ def setup_network(self):
4243
def test_channel_policies(self):
4344
self.log.info("Ensuring node-level channel policy settings")
4445
graphs = []
46+
47+
def ln_node_has_n_edges(
48+
ln: str,
49+
n: int,
50+
) -> Optional[str]:
51+
res = self.warnet(f"ln rpc {ln} describegraph")
52+
edges = json.loads(res)["edges"]
53+
if len(edges) != n:
54+
return None
55+
return edges
56+
4557
for n in range(10):
4658
ln = f"tank-{n:04d}-ln"
47-
res = self.warnet(f"ln rpc {ln} describegraph")
48-
graphs.append(json.loads(res)["edges"])
59+
partial_fn = partial(ln_node_has_n_edges, ln, 13)
60+
edges = self.wait_for_predicate(partial_fn)
61+
graphs.append(edges)
4962

5063
def check_policy(node: int, index: int, field: str, values: tuple):
5164
self.log.info(f"Checking policy: Node={node} ch={index} Expected={field}:{values}")

test/test_base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def wait_for_predicate(self, predicate, timeout=5 * 60, interval=5):
8383
self.log.debug(f"Waiting for predicate with timeout {timeout}s and interval {interval}s")
8484
while timeout > 0:
8585
try:
86-
if predicate():
87-
return
86+
result = predicate()
87+
if result:
88+
return result
8889
except Exception:
8990
pass
9091
sleep(interval)

0 commit comments

Comments
 (0)