Skip to content

Commit

Permalink
add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmyger committed Oct 23, 2024
1 parent 8c7b9e5 commit 0e51618
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions test/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ timeout = 900

# Disable legacy paths.
addopts = -p no:legacypath

log_level = INFO # DEBUG
log_format = %(asctime)s [%(levelname)s] %(name)s/%(funcName)s: %(message)s
log_date_format = %Y-%m-%d %H:%M:%S.%f
31 changes: 25 additions & 6 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,13 @@ def Wait(self, timeout=None) -> int | None:
)
return result_code
log.error(f"Process Wait() timeout after {timeout} seconds; {e}")
if self.stdout and self.stdout.readable():
stdout = "\n".join(self.stdout.readlines())
log.warning(f"Process has stdout={stdout}")
if self.stderr and self.stderr.readable():
stderr = "\n".join(self.stderr.readlines())
stdout = _read_stream(self.stdout)
if stdout:
output = "\n".join(stdout)
log.warning(f"Process has stdout={output}")
stderr = _read_stream(self.stderr)
if stdout:
output = "\n".join(stderr)
log.warning(f"Process has stderr={stderr}")
return None

Expand All @@ -648,32 +650,49 @@ def __del__(self):

class Timeout(Timer):
__timeout: float
__is_running: bool

def __init__(self, name, timeout, callback, *args) -> None:
self.__timeout = timeout
self.__is_running = False
if self.is_timeout:
super().__init__(timeout, callback, *args)
self.setName(name)

@property
def is_timeout(self) -> bool:
return self.__timeout > 0
return self.__timeout is not None and self.__timeout > 0

def __enter__(self):
assert not self.__is_running, "This timer already in use"
if self.is_timeout:
self.__is_running = True
logging.getLogger(__name__).debug(
f"Start timer='{self.name}' for {self.__timeout} seconds {self.args}"
)
self.start()
return self

def __exit__(self, unused_exc_type, unused_value, unused_traceback) -> None:
_ = (unused_exc_type, unused_value, unused_traceback)
if self.is_timeout:
logging.getLogger(__name__).debug(f"Stop(1) timer='{self.name}' {self.args}")
self.cancel()

def __del__(self) -> None:
if self.is_timeout:
logging.getLogger(__name__).debug(f"Stop(2) timer='{self.name}' {self.args}")
self.cancel()


def _read_stream(stream) -> list[str]:
output = []
if stream:
while stream.readable():
output.append(stream.readline().decode())
return output


def _make_string_list(*args) -> list[str]:
result: list[str] = []
for s in args:
Expand Down

0 comments on commit 0e51618

Please sign in to comment.