Skip to content

Commit

Permalink
Allow customising runner timeout on command line
Browse files Browse the repository at this point in the history
  • Loading branch information
baldurk committed Dec 17, 2024
1 parent 8634d8f commit 9de148c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions util/test/rdtest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def get_tests():
return testcases


RUNNER_TIMEOUT = 90 # Require output every X seconds
RUNNER_DEBUG = False # Debug test runner running by printing messages to track it


Expand All @@ -45,7 +44,7 @@ def _enqueue_output(process: subprocess.Popen, out, q: queue.Queue):
pass


def _run_test(testclass, failedcases: list):
def _run_test(testclass, runner_timeout, failedcases: list):
name = testclass.__name__

# Fork the interpreter to run the test, in case it crashes we can catch it.
Expand Down Expand Up @@ -88,7 +87,7 @@ def _run_test(testclass, failedcases: list):
print("Checking runner output...")

try:
out = test_stdout.get(timeout=RUNNER_TIMEOUT)
out = test_stdout.get(timeout=runner_timeout)
while not test_stdout.empty():
out += test_stdout.get_nowait()

Expand Down Expand Up @@ -144,10 +143,10 @@ def _run_test(testclass, failedcases: list):
break

if out is None and err is None and test_run.poll() is None:
log.error('Timed out, no output within {}s elapsed'.format(RUNNER_TIMEOUT))
log.error('Timed out, no output within {}s elapsed'.format(runner_timeout))
test_run.kill()
test_run.communicate()
raise subprocess.TimeoutExpired(' '.join(args), RUNNER_TIMEOUT)
raise subprocess.TimeoutExpired(' '.join(args), runner_timeout)

if RUNNER_DEBUG:
print("Test runner has finished")
Expand Down Expand Up @@ -189,7 +188,7 @@ def fetch_tests():
return { x[0]: (x[1] == 'True', x[2]) for x in split_tests }


def run_tests(test_include: str, test_exclude: str, in_process: bool, slow_tests: bool, debugger: bool):
def run_tests(test_include: str, test_exclude: str, in_process: bool, slow_tests: bool, debugger: bool, test_timeout: int):
start_time = datetime.datetime.now(datetime.timezone.utc)

rd.InitialiseReplay(rd.GlobalEnvironment(), [])
Expand Down Expand Up @@ -348,7 +347,7 @@ def do(debugMode):
if in_process:
instance.invoketest(debugMode)
else:
_run_test(testclass, failedcases)
_run_test(testclass, test_timeout, failedcases)

if debugger:
do(True)
Expand Down
4 changes: 3 additions & 1 deletion util/test/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
help="Run test code in the same process as test runner", action="store_true")
parser.add_argument('--slow-tests',
help="Run potentially slow tests", action="store_true")
parser.add_argument('--test-timeout',
help="Timeout for output from tests", default=90, type=int)
parser.add_argument('--data', default=os.path.join(script_dir, "data"),
help="The folder that reference data is in. Will not be modified.", type=str)
parser.add_argument('--demos-binary', default="",
Expand Down Expand Up @@ -137,4 +139,4 @@
elif args.internal_run_test is not None:
rdtest.internal_run_test(args.internal_run_test)
else:
rdtest.run_tests(args.test_include, args.test_exclude, args.in_process, args.slow_tests, args.debugger)
rdtest.run_tests(args.test_include, args.test_exclude, args.in_process, args.slow_tests, args.debugger, args.test_timeout)

0 comments on commit 9de148c

Please sign in to comment.