Skip to content

Commit 9f41fcf

Browse files
committed
Lower retagger per-test timeout
1 parent 3839118 commit 9f41fcf

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
else:
5151
TAGS_DIR = "null"
5252

53-
TIMEOUT = 90 * 60
53+
RUN_TIMEOUT = 90 * 60
54+
RETAG_TIMEOUT = 20 * 60
5455
RUNNER = os.path.join(os.path.dirname(__file__), "run_cpython_test.py")
5556
LINE = "=" * 80
5657

@@ -107,14 +108,16 @@ def test_tagged():
107108
if os.environ.get("ENABLE_THREADED_GRAALPYTEST") == "true":
108109
run_serialize_out(cmd)
109110
else:
110-
rcode = run_with_timeout(cmd).returncode
111+
rcode = run_with_timeout(cmd, timeout=RUN_TIMEOUT).returncode
111112
if rcode:
112113
raise subprocess.CalledProcessError(rcode, cmd)
113114
print(working_test[0], "was finished.")
114115

115116
def run_serialize_out(cmd):
116-
result = run_with_timeout(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
117+
result = run_with_timeout(cmd, timeout=RUN_TIMEOUT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
117118
append_out = "-v" in sys.argv
119+
if result.returncode == 124:
120+
raise subprocess.TimeoutExpired(cmd=cmd, timeout=RUN_TIMEOUT)
118121
if result.returncode:
119122
message = f"{working_test[0]} failed with exit code {result.returncode}.\n"
120123
append_out = True
@@ -196,14 +199,14 @@ def parse_unittest_output(output):
196199
return
197200

198201

199-
def run_with_timeout(cmd, *args, **kwargs):
202+
def run_with_timeout(cmd, *, timeout, **kwargs):
200203
p = subprocess.getstatusoutput("which timeout" if sys.platform != 'darwin' else "which gtimeout")
201204
if p[0] != 0:
202205
print("Cannot find the 'timeout' GNU tool. Do you have coreutils installed?")
203206
else:
204-
timeout = p[1].strip()
205-
cmd = [timeout, "-s", "9", str(TIMEOUT)] + cmd
206-
return subprocess.run(cmd, *args, **kwargs)
207+
timeout_cmd = p[1].strip()
208+
cmd = [timeout_cmd, "-k", "10", str(timeout)] + cmd
209+
return subprocess.run(cmd, **kwargs)
207210

208211

209212
def main():
@@ -213,21 +216,23 @@ def main():
213216
glob_pattern = os.path.join(os.path.dirname(test.__file__), "test_*.py")
214217
retag = False
215218
maxrepeats = 4
219+
timeout = None
216220
for arg in sys.argv[1:]:
217221
if arg == "--retag":
218222
retag = True
219223
elif arg.startswith("--maxrepeats="):
220224
maxrepeats = int(arg.partition("=")[2])
221225
elif arg.startswith("--timeout="):
222-
global TIMEOUT
223-
TIMEOUT = arg.partition("=")[2]
226+
timeout = int(arg.partition("=")[2])
224227
elif arg == "--help":
225228
print(sys.argv[0] + " [--retag] [--maxrepeats=n] [glob]")
226229
else:
227230
if not (arg.endswith(".py") or arg.endswith("*")):
228231
arg += ".py"
229232
glob_pattern = os.path.join(os.path.dirname(test.__file__), arg)
230233

234+
if not timeout:
235+
timeout = RETAG_TIMEOUT if retag else RUN_TIMEOUT
231236
testfiles = glob.glob(glob_pattern)
232237
testfiles += glob.glob(glob_pattern.replace(".py", "/__init__.py"))
233238

@@ -268,15 +273,15 @@ def main():
268273
cmd.append(testfile)
269274

270275
print(shlex.join(cmd))
271-
p = run_with_timeout(cmd, errors='backslashreplace', **kwargs)
276+
p = run_with_timeout(cmd, timeout=timeout, errors='backslashreplace', **kwargs)
272277
print("*stdout*")
273278
print(p.stdout)
274279
print("*stderr*")
275280
print(p.stderr)
276281

277-
if p.returncode == -9:
282+
if p.returncode == 124:
278283
print(
279-
f"\nTimeout (return code -9)\nyou can try to increase the current timeout {TIMEOUT}s by using --timeout=NNN")
284+
f"\nTimed out\nYou can try to increase the current timeout {timeout}s by using --timeout=NNN")
280285

281286
passing_tests = set()
282287
failing_tests = set()

mx.graalpython/mx_graalpython.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def retag_unittests(args):
422422
parser.add_argument('--inspect', action='store_true')
423423
parser.add_argument('-debug-java', action='store_true')
424424
parser.add_argument('--jvm', action='store_true')
425+
parser.add_argument('--timeout')
425426
parsed_args, remaining_args = parser.parse_known_args(args)
426427
env = os.environ.copy()
427428
env.update(
@@ -441,6 +442,8 @@ def retag_unittests(args):
441442
'graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py',
442443
'--retag'
443444
]
445+
if parsed_args.timeout:
446+
args += [f'--timeout={parsed_args.timeout}']
444447
vm = python_svm() if not parsed_args.jvm else python_gvm()
445448
if parsed_args.jvm:
446449
args += ['-ea']

0 commit comments

Comments
 (0)