Skip to content

Commit bfbca03

Browse files
author
macgyver13
committed
- Add local_test_runner script
- add delay to graph_test expect - increases reliability
1 parent 24b4969 commit bfbca03

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

test/graph_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
import json
4-
import os
4+
import os, time
55

66
import pexpect
77
from test_base import TestBase
@@ -39,21 +39,29 @@ def directory_exists(self):
3939
self.sut = pexpect.spawn("warnet create")
4040
self.sut.expect("name", timeout=10)
4141
self.sut.sendline("ANewNetwork")
42+
time.sleep(.1)
4243
self.sut.expect("many", timeout=10)
4344
self.sut.sendline("")
45+
time.sleep(.1)
4446
self.sut.expect("connections", timeout=10)
4547
self.sut.sendline("")
48+
time.sleep(.1)
4649
self.sut.expect("version", timeout=10)
4750
self.sut.sendline("")
51+
time.sleep(.1)
4852
self.sut.expect("enable fork-observer", timeout=10)
4953
self.sut.sendline("")
54+
time.sleep(.1)
5055
self.sut.expect("seconds", timeout=10)
5156
self.sut.sendline("")
57+
time.sleep(.1)
5258
self.sut.expect("enable grafana", timeout=10)
5359
self.sut.sendline("")
60+
time.sleep(.1)
5461
self.sut.expect("successfully", timeout=50)
5562
except Exception as e:
5663
print(f"\nReceived prompt text:\n {self.sut.before.decode('utf-8')}\n")
64+
print(os.listdir(self.tmpdir))
5765
raise e
5866

5967
def run_created_network(self):

test/local_test_runner.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import yaml
2+
import subprocess, sys
3+
4+
# developers can use this tool to verify all repo workflow test execute to completion
5+
#
6+
# execute from repo root like this to execute all tests
7+
# python test/local_test_runner.py
8+
#
9+
# add optional argument to just execute any matching tests
10+
# python test/local_test_runner.py [ln_ | graph]
11+
12+
13+
def has_key_path(d, key_path, separator="."):
14+
"""Check if a nested key path (dotted notation) exists in a dictionary."""
15+
keys = key_path.split(separator)
16+
for key in keys:
17+
if not isinstance(d, dict) or key not in d:
18+
return False
19+
d = d[key]
20+
return True
21+
22+
# Load the workflow file
23+
with open('.github/workflows/test.yml', 'r') as file:
24+
workflow = yaml.safe_load(file)
25+
26+
tests_total=0
27+
tests_skipped=0
28+
tests_completed=0
29+
30+
for job_name, job_details in workflow.get("jobs", {}).items():
31+
if has_key_path(job_details, "strategy.matrix.test"):
32+
print("Found test strategy job, starting serial execution of each test")
33+
tests = job_details["strategy"]["matrix"]["test"]
34+
35+
for test in tests:
36+
tests_total+=1
37+
if len(sys.argv) > 1 and sys.argv[1] not in test:
38+
print("skipping test as requested:",test)
39+
tests_skipped+=1
40+
continue
41+
command = f"python test/{test}"
42+
print("###################################################################################################")
43+
print("############## executing:", command)
44+
print("###################################################################################################")
45+
process = subprocess.run(command, shell=True)
46+
if process.returncode != 0:
47+
print("******** testing failed")
48+
if process.stdout: print("stdout:", process.stdout)
49+
if process.stderr: print("stderr:", process.stderr)
50+
sys.exit(1)
51+
tests_completed+=1
52+
53+
print("###################################################################################################")
54+
print("testing complete")
55+
print(f"{tests_completed} of {tests_total} complete - skipped: {tests_skipped} tests")
56+
print("###################################################################################################")

0 commit comments

Comments
 (0)