Skip to content

Commit

Permalink
test_nodes update
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Nov 1, 2023
1 parent 09af677 commit 7195626
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions .ci/tests/examples/wait_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,31 @@ def _test_rounds(n_rounds):
return n == n_rounds


def _test_nodes(n_nodes, node_type, reducer_host='localhost', reducer_port='8090'):
def _test_nodes(n_nodes, node_type, reducer_host='localhost', reducer_port='8092'):
try:
resp = requests.get(
f'http://{reducer_host}:{reducer_port}/netgraph', verify=False)

endpoint = "list_clients" if node_type == "client" else "list_combiners"

response = requests.get(
f'http://{reducer_host}:{reducer_port}/{endpoint}', verify=False)

if response.status_code == 200:

data = json.loads(response.content)

count = 0
if node_type == "client":
arr = data.get('result')
count = sum(element.get('status') == "online" for element in arr)
else:
count = data.get('count')

_eprint(f'Active {node_type}s: {count}.')
return count == n_nodes

except Exception as e:
_eprint(f'Reques exception econuntered: {e}.')
return False
if resp.status_code == 200:
gr = json.loads(resp.content)

status_key = "online" if node_type == "client" else "active"

n = sum(values.get('type') == node_type and values.get(
'status') == status_key for values in gr['nodes'])
_eprint(f'Active {node_type}s: {n}.')
return n == n_nodes
_eprint(f'Reducer returned {resp.status_code}.')
return False


def rounds(n_rounds=3):
Expand Down

0 comments on commit 7195626

Please sign in to comment.