Skip to content

Commit

Permalink
Enlarge abort_wait_timeout to fix leftover driver when abort testplan…
Browse files Browse the repository at this point in the history
… from interactive UI. (#992)

Co-authored-by: Pyifan <[email protected]>
  • Loading branch information
Pyifan and Pyifan authored Sep 27, 2023
1 parent c8fe0a1 commit 022fb82
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions examples/Transports/FIX/over_one_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def get_multitest():
target="ISLD",
msgclass=FixMessage,
codec=CODEC,
logoff_at_stop=False,
),
],
)
Expand Down
20 changes: 18 additions & 2 deletions testplan/common/entity/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def get_options(cls):
ConfigOption("initial_context", default={}): dict,
ConfigOption("path_cleanup", default=False): bool,
ConfigOption("status_wait_timeout", default=600): int,
ConfigOption("abort_wait_timeout", default=30): int,
ConfigOption("abort_wait_timeout", default=300): int,
ConfigOption("active_loop_sleep", default=0.005): float,
}

Expand Down Expand Up @@ -632,7 +632,15 @@ def _abort_entity(self, entity, wait_timeout=None):
self.logger.error(traceback.format_exc())
self.logger.error("Exception on aborting %s - %s", entity, exc)
else:
if wait(lambda: entity.aborted is True, timeout) is False:

if (
wait(
predicate=lambda: entity.aborted is True,
timeout=timeout,
raise_on_timeout=False, # continue even if some entity timeout
)
is False
):
self.logger.error("Timeout on waiting to abort %s.", entity)

def aborting(self):
Expand Down Expand Up @@ -1133,9 +1141,16 @@ def run(self):
while self._ihandler.active:
time.sleep(self.cfg.active_loop_sleep)
else:
# TODO: need some rework
# if we abort from ui, the ihandler.abort executes in http thread
# if we abort by ^C, ihandler.abort is called in main thread
# anyway this join will not be blocked
interruptible_join(
thread, timeout=self.cfg.abort_wait_timeout
)
# if we abort from ui, we abort ihandler first, then testrunner
# this abort will wait ihandler to be aborted
# if we abort by ^C, testrunner.abort is already called, this will be noop
self.abort()
return self._ihandler
else:
Expand Down Expand Up @@ -1693,6 +1708,7 @@ def _handle_abort(self, signum, frame):
signum,
threading.current_thread(),
)

self.abort()

def pausing(self):
Expand Down
14 changes: 8 additions & 6 deletions testplan/runnable/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def result_for_failed_task(original_result):
"""
result = TestResult()
result.report = TestGroupReport(
name=original_result.task.name, category=ReportCategories.ERROR
name=str(original_result.task), category=ReportCategories.ERROR
)
attrs = [attr for attr in original_result.task.serializable_attrs]
result_lines = [
Expand Down Expand Up @@ -957,14 +957,16 @@ def _wait_ongoing(self):

while self.active:
if self.cfg.timeout and time.time() - _start_ts > self.cfg.timeout:
self.result.test_report.logger.error(
"Timeout: Aborting execution after %d seconds",
self.cfg.timeout,
msg = (
f"Timeout: Aborting execution after {self.cfg.timeout} seconds",
)
# Abort dependencies, wait sometime till test reports are ready
self.result.test_report.logger.error(msg)
self.logger.error(msg)

# Abort resources e.g pools
for dep in self.abort_dependencies():
self._abort_entity(dep)
time.sleep(self.cfg.abort_wait_timeout)

break

pending_work = False
Expand Down
4 changes: 2 additions & 2 deletions testplan/runners/pools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,11 @@ def _discard_pending_tasks(self):
self.logger.critical("Discard pending tasks of %s", self)
while self.ongoing:
uid = self.ongoing[0]
target = self._input[uid]._target
task = self._input[uid]
self._results[uid] = TaskResult(
task=self._input[uid],
status=False,
reason=f"Task [{target}] discarding due to {self} abort",
reason=f"{task} discarding due to {self} abort",
)
self.ongoing.pop(0)

Expand Down
23 changes: 10 additions & 13 deletions testplan/runners/pools/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import OrderedDict
from typing import Optional, Tuple, Union, Dict, Sequence, Callable

from testplan.common.entity import Runnable
from testplan.testing.base import Test, TestResult
from testplan.common.serialization import SelectiveSerializable
from testplan.common.utils import strings
Expand Down Expand Up @@ -85,7 +86,15 @@ def __init__(
self._part = part

def __str__(self) -> str:
return "{}[{}]".format(self.__class__.__name__, self._uid)
if isinstance(self._target, Runnable):
name = (
getattr(self._target, "name", None)
or self._target.__class__.__name__
)
else:
name = self._target

return f"{self.__class__.__name__}[{name}(uid={self._uid})]"

@property
def weight(self) -> int:
Expand All @@ -111,18 +120,6 @@ def uid(self) -> str:
"""Task string uid."""
return self._uid

@property
def name(self) -> str:
"""Task name."""
if not isinstance(self._target, str):
try:
name = self._target.__class__.__name__
except AttributeError:
name = self._target
else:
name = self._target
return "Task[{}]".format(name)

@property
def args(self) -> Tuple:
"""Task target args."""
Expand Down

0 comments on commit 022fb82

Please sign in to comment.