Skip to content

Commit 89eb658

Browse files
benoit-nexthopmeta-codesync[bot]
authored andcommitted
Allow passing a timeout to unit tests
Summary: **Pre-submission checklist** - [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install` - [x] `pre-commit run` When running unit tests, no timeout was enforced. Add an optional `--timeout` flag to `getdeps.py` that is passed to `ctest` and update our build script to set a default timeout of 90 seconds per test, which is generous enough for now. X-link: facebook/fboss#654 Reviewed By: ahornby Differential Revision: D86883098 Pulled By: KevinYakar fbshipit-source-id: 9c841311460a546ae9189ddf62ee461aad948871
1 parent 42abf6a commit 89eb658

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

build/fbcode_builder/getdeps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ def run_project_cmd(self, args, loader, manifest):
940940
test_filter=args.filter,
941941
retry=args.retry,
942942
no_testpilot=args.no_testpilot,
943+
timeout=args.timeout,
943944
)
944945

945946
def setup_project_cmd_parser(self, parser):
@@ -957,6 +958,12 @@ def setup_project_cmd_parser(self, parser):
957958
help="Do not use Test Pilot even when available",
958959
action="store_true",
959960
)
961+
parser.add_argument(
962+
"--timeout",
963+
type=int,
964+
default=None,
965+
help="Timeout in seconds for each individual test",
966+
)
960967

961968

962969
@cmd(

build/fbcode_builder/getdeps/builder.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ def num_jobs(self) -> int:
238238
)
239239
)
240240

241-
def run_tests(self, schedule_type, owner, test_filter, retry, no_testpilot) -> None:
241+
def run_tests(
242+
self, schedule_type, owner, test_filter, retry, no_testpilot, timeout=None
243+
) -> None:
242244
"""Execute any tests that we know how to run. If they fail,
243245
raise an exception."""
244246
pass
@@ -343,7 +345,9 @@ def _build(self, reconfigure) -> None:
343345
for file in glob.glob(srcpattern):
344346
shutil.copy(file, libdir)
345347

346-
def run_tests(self, schedule_type, owner, test_filter, retry, no_testpilot) -> None:
348+
def run_tests(
349+
self, schedule_type, owner, test_filter, retry, no_testpilot, timeout=None
350+
) -> None:
347351
if not self.test_args:
348352
return
349353

@@ -358,6 +362,9 @@ def run_tests(self, schedule_type, owner, test_filter, retry, no_testpilot) -> N
358362
else:
359363
env["GETDEPS_TEST_RETRY"] = 0
360364

365+
if timeout is not None:
366+
env["GETDEPS_TEST_TIMEOUT"] = str(timeout)
367+
361368
cmd = (
362369
[self._make_binary, "-j%s" % self.num_jobs]
363370
+ self.test_args
@@ -919,7 +926,7 @@ def _build(self, reconfigure: bool) -> None:
919926
)
920927

921928
def run_tests(
922-
self, schedule_type, owner, test_filter, retry: int, no_testpilot
929+
self, schedule_type, owner, test_filter, retry: int, no_testpilot, timeout=None
923930
) -> None:
924931
env = self._compute_env()
925932
ctest = path_search(env, "ctest")
@@ -1066,6 +1073,9 @@ def list_tests():
10661073
if run_id is not None:
10671074
testpilot_args += ["--run-id", run_id]
10681075

1076+
if timeout is not None:
1077+
testpilot_args += ["--timeout", str(timeout)]
1078+
10691079
if test_filter:
10701080
testpilot_args += ["--", test_filter]
10711081

@@ -1126,6 +1136,8 @@ def list_tests():
11261136
]
11271137
if test_filter:
11281138
args += ["-R", test_filter]
1139+
if timeout is not None:
1140+
args += ["--timeout", str(timeout)]
11291141

11301142
count = 0
11311143
retcode = -1
@@ -1421,7 +1433,9 @@ def _build(self, reconfigure) -> None:
14211433
with open(os.path.join(self.inst_dir, ".built-by-getdeps"), "w") as f:
14221434
f.write("built")
14231435

1424-
def run_tests(self, schedule_type, owner, test_filter, retry, no_testpilot) -> None:
1436+
def run_tests(
1437+
self, schedule_type, owner, test_filter, retry, no_testpilot, timeout=None
1438+
) -> None:
14251439
# setup.py actually no longer has a standard command for running tests.
14261440
# Instead we let manifest files specify an arbitrary Python file to run
14271441
# as a test.

build/fbcode_builder/getdeps/cargo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def _build(self, reconfigure) -> None:
203203
build_source_dir, os.path.join(self.inst_dir, "source")
204204
)
205205

206-
def run_tests(self, schedule_type, owner, test_filter, retry, no_testpilot) -> None:
206+
def run_tests(
207+
self, schedule_type, owner, test_filter, retry, no_testpilot, timeout=None
208+
) -> None:
207209
if test_filter:
208210
args = ["--", test_filter]
209211
else:

0 commit comments

Comments
 (0)