Skip to content

Commit 2183fe4

Browse files
committed
Validate topologies
1 parent 50768ce commit 2183fe4

3 files changed

Lines changed: 73 additions & 3 deletions

File tree

.github/workflows/tester.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ jobs:
2222
- name: Perform perf test 1 - Random
2323
run: |
2424
python ./test/perf/node_utils.py file ./test/perf/topology-random.yaml&
25-
sleep 10
25+
python ./test/perf/node_utils.py dot-compare graph_controller.dot last-topology_graph.dot --wait 40
2626
python ./test/perf/node_utils.py ping ./test/perf/topology-random.yaml --count 100 --validate 0.1
2727
kill `pidof python`
2828
rm -Rf /tmp/receptor
29+
rm graph_controller.dot
30+
rm last-topology_graph.dot
2931
- name: Upload artifact for Perf - Random
3032
uses: actions/upload-artifact@v1
3133
with:
@@ -34,10 +36,12 @@ jobs:
3436
- name: Perform perf test 2 - Flat
3537
run: |
3638
python ./test/perf/node_utils.py file ./test/perf/topology-flat.yaml&
37-
sleep 10
39+
python ./test/perf/node_utils.py dot-compare graph_controller.dot last-topology_graph.dot --wait 40
3840
python ./test/perf/node_utils.py ping ./test/perf/topology-flat.yaml --count 100 --validate 0.1
3941
kill `pidof python`
4042
rm -Rf /tmp/receptor
43+
rm graph_controller.dot
44+
rm last-topology_graph.dot
4145
- name: Upload artifact for Perf - Flat
4246
uses: actions/upload-artifact@v1
4347
with:
@@ -46,10 +50,12 @@ jobs:
4650
- name: Perform perf test 3 - Tree
4751
run: |
4852
python ./test/perf/node_utils.py file ./test/perf/topology-tree.yaml&
49-
sleep 10
53+
python ./test/perf/node_utils.py dot-compare graph_controller.dot last-topology_graph.dot --wait 40
5054
python ./test/perf/node_utils.py ping ./test/perf/topology-tree.yaml --count 100 --validate 0.1
5155
kill `pidof python`
5256
rm -Rf /tmp/receptor
57+
rm graph_controller.dot
58+
rm last-topology_graph.dot
5359
- name: Upload artifact for Perf - Tree
5460
uses: actions/upload-artifact@v1
5561
with:

test/perf/node_utils.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,36 @@
99

1010
import click
1111
import yaml
12+
from pyparsing import alphanums
13+
from pyparsing import Group
14+
from pyparsing import OneOrMore
15+
from pyparsing import ParseException
16+
from pyparsing import Suppress
17+
from pyparsing import Word
1218

1319

1420
DEBUG = False
1521

1622

23+
class Conn:
24+
def __init__(self, a, b):
25+
self.a = a
26+
self.b = b
27+
28+
def __eq__(self, other):
29+
if self.a == other.a and self.b == other.b or self.a == other.b and self.b == other.a:
30+
return True
31+
return False
32+
33+
def __hash__(self):
34+
enps = [self.a, self.b]
35+
sorted_enps = sorted(enps)
36+
return hash(tuple(sorted_enps))
37+
38+
def __repr__(self):
39+
return f"{self.a} -- {self.b}"
40+
41+
1742
def random_port(tcp=True):
1843
"""Get a random port number for making a socket
1944
@@ -268,5 +293,43 @@ def ping(filename, count, validate):
268293
sys.exit(127)
269294

270295

296+
def read_and_parse_dot(filename):
297+
group = Group(Word(alphanums) + Suppress("--") + Word(alphanums)) + Suppress(";")
298+
dot = Suppress("graph {") + OneOrMore(group) + Suppress("}")
299+
300+
with open(filename) as f:
301+
raw_data = f.read()
302+
data = dot.parseString(raw_data).asList()
303+
return {Conn(c[0], c[1]) for c in data}
304+
305+
306+
@main.command("dot-compare")
307+
@click.option("--wait", default=None)
308+
@click.argument("filename_one")
309+
@click.argument("filename_two")
310+
def dot_compare(filename_one, filename_two, wait):
311+
312+
if wait:
313+
start = time.time()
314+
while True:
315+
try:
316+
assert read_and_parse_dot(filename_one) == read_and_parse_dot(filename_two)
317+
sys.stderr.write("Matched\n")
318+
sys.exit(0)
319+
except (AssertionError, ParseException, FileNotFoundError) as e:
320+
if time.time() < start + float(wait):
321+
time.sleep(1)
322+
else:
323+
sys.stderr.write("Failed match\n")
324+
raise e
325+
else:
326+
try:
327+
assert read_and_parse_dot(filename_one) == read_and_parse_dot(filename_two)
328+
sys.stderr.write("Matched\n")
329+
except AssertionError:
330+
sys.stderr.write("Failed match\n")
331+
sys.exit(127)
332+
333+
271334
if __name__ == "__main__":
272335
main()

test/perf/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
click
22
pyyaml
3+
pyparsing

0 commit comments

Comments
 (0)