7 script_path = os.path.dirname(os.path.realpath(sys.argv[0]))
13 print(
"junitparser module was not found, installing...")
14 subprocess.call([os.path.join(
'.', script_path,
'test_installer.sh')])
16 from junitparser
import TestCase, TestSuite, JUnitXml, Skipped, Element
24 def __init__(self, inlinemsg=None, message=None, type_=None):
27 if inlinemsg
is not None:
36 super().
__init__(message=message, type_=type_)
49 BIN_NAME = os.path.join(
'.', script_path,
'swarmio-simulator')
50 PROCESS_START_DELAY_S = 1
54 files = os.listdir(
'.')
55 proc1 = subprocess.Popen(BIN_NAME, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
56 time.sleep(PROCESS_START_DELAY_S)
58 new_files = os.listdir(
'.')
59 proc1_log = [f
for f
in new_files
if f
not in files][0]
61 files = os.listdir(
'.')
62 proc2 = subprocess.Popen(BIN_NAME, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
64 time.sleep(PROCESSES_RUN_S)
67 program_starting_case = TestCase(
'program_starting_case')
68 discovery_case = TestCase(
'discovery_case')
71 out, err = proc1.communicate(input=b
'\n', timeout=PROCESS_TIMEOUT_S)
72 proc1_out = out.decode(
'unicode_escape').split(
'\n')
73 out, err = proc2.communicate(input=b
'\n', timeout=PROCESS_TIMEOUT_S)
74 proc2_out = out.decode(
'unicode_escape').split(
'\n')
76 new_files = os.listdir(
'.')
77 proc2_log = [f
for f
in new_files
if f
not in files][0]
80 found_other_node =
False 81 with open(log_fname)
as fp:
82 for i, line
in enumerate(fp):
85 spl = line.split(
'\t')
88 if other_node
in line:
89 found_other_node =
True 93 elif 'log format' in line.lower():
94 s = line.find(
'[') + 1
97 return found_other_node
99 uuidpos = proc2_out[0].find(
'UUID: ') + len(
'UUID: ')
100 proc1_found_proc2 =
parse_log(proc1_log, proc2_out[0][uuidpos:])
101 proc2_found_proc1 =
parse_log(proc2_log, proc1_out[0][uuidpos:])
105 if proc1_found_proc2
and proc2_found_proc1:
106 discovery_case.result =
Success()
108 discovery_case.result =
Failure(message=
'discovery error')
110 if proc1.poll() ==
None:
113 if proc2.poll() ==
None:
117 program_starting_case.result =
Failure(message=
'program crash error')
118 discovery_case.result =
Failure(message=
'discovery error')
121 suite = TestSuite(
'testsuite')
123 suite.add_testcase(program_starting_case)
124 suite.add_testcase(discovery_case)
128 xml.add_testsuite(suite)
130 test_reporst_dir = os.path.join(
'tests',
'test-reports')
131 if not os.path.exists(test_reporst_dir):
132 os.makedirs(test_reporst_dir)
134 xml.write(os.path.join(test_reporst_dir,
'result.xml'), pretty=
True)
def __init__(self, inlinemsg=None, message=None, type_=None)
def parse_log(log_fname, other_node)