From: Nicki Křížek Date: Mon, 23 Jun 2025 12:37:09 +0000 (+0200) Subject: Split up waiting for match to a separate WatchLog method X-Git-Tag: v9.21.11~40^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=365f8b6af6e213398ad7d9084b0ebf9140b0933b;p=thirdparty%2Fbind9.git Split up waiting for match to a separate WatchLog method To allow re-use in upcoming functions, isolate the line matching logic into a separate function. Use an instance-wide deadline attribute, which is set by the calling function. --- diff --git a/bin/tests/system/isctest/log/watchlog.py b/bin/tests/system/isctest/log/watchlog.py index 467a935ebce..e1fcaf739d0 100644 --- a/bin/tests/system/isctest/log/watchlog.py +++ b/bin/tests/system/isctest/log/watchlog.py @@ -98,6 +98,7 @@ class WatchLog(abc.ABC): if timeout <= 0.0: raise WatchLogException("timeout must be greater than 0") self._timeout = timeout + self._deadline = 0.0 def _readline(self) -> Optional[str]: """ @@ -250,16 +251,22 @@ class WatchLog(abc.ABC): """ regexes = self._prepare_patterns(patterns) self._wait_function_called = True + self._deadline = time.monotonic() + self._timeout - deadline = time.monotonic() + self._timeout - while time.monotonic() < deadline: + return self._wait_for_match(regexes) + + def _wait_for_match(self, regexes: List[Pattern]) -> Match: + while time.monotonic() < self._deadline: for line in self._readlines(): for regex in regexes: match = regex.search(line) if match: return match time.sleep(0.1) - raise TimeoutError(f"Timeout reached watching {self._path} for {patterns}") + raise TimeoutError( + f"Timeout reached watching {self._path} for " + f"{' | '.join([regex.pattern for regex in regexes])}" + ) def __enter__(self) -> Any: self._fd = open(self._path, encoding="utf-8")