forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- A per-target test timeout can be configured in the `BUILD` file with `timeout=SECONDS` - Because pants may run many targets tests as once, the timeouts for all the tests are summed for the entire run of tests timeout - If one of the targets has no timeout, then all the tests run with no timeout - A default timeout can be configured with the `--timeout-default` option - Timeouts can be [disabled]/enabled with `--[no-]timeouts` - Sets the default timeout to 1 minute for java & python tests in `pants.ini` Testing Done: ./pants test tests/python/pants_test:all ./pants test tests/python/pants_test/backend/jvm/tasks:junit_run_integration - Added tests: * tests/python/pants_test/util:timeout * tests/python/pants_test/backend/python/tasks:pytest_run * tests/python/pants_test/backend/jvm/tasks:junit_run * tests/python/pants_test/backend/core/tasks:test_task_mixin Pull Request: pantsbuild#2243 Reviewed at https://rbcommons.com/s/twitter/r/2919/
- Loading branch information
1 parent
987d830
commit 93edf2f
Showing
15 changed files
with
415 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# coding=utf-8 | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import sys | ||
import thread | ||
import threading | ||
|
||
|
||
class TimeoutReached(Exception): | ||
def __init__(self, seconds): | ||
super(TimeoutReached, self).__init__("Timeout of {} seconds reached".format(seconds)) | ||
|
||
|
||
class Timeout(object): | ||
"""Timeout generator. If seconds is None or 0, then the there is no timeout. | ||
try: | ||
with Timeout(seconds): | ||
<do stuff> | ||
except TimeoutReached: | ||
<handle timeout> | ||
""" | ||
|
||
def __init__(self, seconds, threading_timer=threading.Timer): | ||
|
||
# self._triggered is not protected by a mutex because boolean set/get is atomic in all the Python | ||
# implementations we care about. | ||
self._triggered = False | ||
self._seconds = seconds | ||
|
||
if self._seconds: | ||
self._timer = threading_timer(self._seconds, self._handle_timeout) | ||
else: | ||
self._timer = None | ||
|
||
def _handle_timeout(self): | ||
sys.stderr.flush() # Python 3 stderr is likely buffered. | ||
self._triggered = True | ||
thread.interrupt_main() # Raises KeyboardInterrupt. | ||
|
||
def __enter__(self): | ||
if self._timer is not None: | ||
self._timer.start() | ||
|
||
def __exit__(self, type_, value, traceback): | ||
"""If triggered, raise TimeoutReached. | ||
Rather than converting a KeyboardInterrupt to TimeoutReached here, we just check self._triggered, | ||
which helps us in the case where the thread we are trying to timeout isn't the main thread. Of | ||
course in that case the executing doesn't get interrupted at the appropriate time, but at least | ||
the exception still gets raised. | ||
""" | ||
if self._triggered: | ||
raise TimeoutReached(self._seconds) | ||
|
||
elif self._timer is not None: | ||
self._timer.cancel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.