|
44 | 44 | import subprocess
|
45 | 45 | from collections import defaultdict
|
46 | 46 | from json import dumps
|
47 |
| -from multiprocessing import Pool |
| 47 | +from multiprocessing import Pool, TimeoutError |
48 | 48 | from pprint import pformat
|
49 | 49 |
|
50 | 50 | import argparse
|
@@ -136,19 +136,41 @@ def _run_unittest(test_path):
|
136 | 136 | return success, output
|
137 | 137 |
|
138 | 138 |
|
139 |
| -def run_unittests(unittests): |
| 139 | +TIMEOUT = 60 * 20 # 20 mins per unittest wait time max ... |
| 140 | + |
| 141 | + |
| 142 | +def run_unittests(unittests, timeout): |
140 | 143 | assert isinstance(unittests, (list, tuple))
|
141 | 144 | num_unittests = len(unittests)
|
142 | 145 | log("[EXEC] running {} unittests ... ", num_unittests)
|
| 146 | + log("[EXEC] timeout per unittest: {} seconds", timeout) |
143 | 147 | results = []
|
144 | 148 |
|
145 | 149 | pool = Pool()
|
146 | 150 | for ut in unittests:
|
147 | 151 | results.append(pool.apply_async(_run_unittest, args=(ut, )))
|
148 | 152 | pool.close()
|
149 |
| - pool.join() |
150 | 153 |
|
151 |
| - return [res.get()[1] for res in results] |
| 154 | + log("[INFO] collect results ... ") |
| 155 | + out = [] |
| 156 | + timed_out = [] |
| 157 | + for i, res in enumerate(results): |
| 158 | + try: |
| 159 | + _, output = res.get(timeout) |
| 160 | + out.append(output) |
| 161 | + log("[PROGRESS] {} / {}, \t\t {}%", i, num_unittests, int((i * 100.0) / num_unittests)) |
| 162 | + except TimeoutError: |
| 163 | + log("[ERR] timeout while getting results for {}, skipping!", unittests[i]) |
| 164 | + timed_out.append(unittests[i]) |
| 165 | + |
| 166 | + log("".join(['-' for i in range(120)])) |
| 167 | + for t in timed_out: |
| 168 | + log("[TIMEOUT] skipped: {}", t) |
| 169 | + log("".join(['-' for i in range(120)])) |
| 170 | + |
| 171 | + pool.terminate() |
| 172 | + pool.join() |
| 173 | + return out |
152 | 174 |
|
153 | 175 |
|
154 | 176 | def get_unittests(base_tests_path, limit=None, sort=True, skip_tests=None):
|
@@ -628,6 +650,7 @@ def main(prog, args):
|
628 | 650 | parser.add_argument("-v", "--verbose", help="Verbose output.", action="store_true")
|
629 | 651 | parser.add_argument("-l", "--limit", help="Limit the number of unittests to run.", default=None, type=int)
|
630 | 652 | parser.add_argument("-t", "--tests_path", help="Unittests path.", default=PATH_UNITTESTS)
|
| 653 | + parser.add_argument("-T", "--timeout", help="Timeout per unittest run.", default=TIMEOUT, type=int) |
631 | 654 | parser.add_argument("-o", "--only_tests", help="Run only these unittests (comma sep values).", default=None)
|
632 | 655 | parser.add_argument("-s", "--skip_tests", help="Run all unittests except (comma sep values)."
|
633 | 656 | "the only_tets option takes precedence", default=None)
|
@@ -656,7 +679,7 @@ def _fmt(t):
|
656 | 679 | skip_tests = set([_fmt(test) for test in flags.skip_tests.split(",")]) if flags.skip_tests else None
|
657 | 680 | unittests = get_unittests(flags.tests_path, limit=flags.limit, skip_tests=skip_tests)
|
658 | 681 |
|
659 |
| - results = run_unittests(unittests) |
| 682 | + results = run_unittests(unittests, flags.timeout) |
660 | 683 | txt_report_path = file_name(TXT_RESULTS_NAME, current_date)
|
661 | 684 | output = save_as_txt(txt_report_path, results)
|
662 | 685 |
|
|
0 commit comments