diff options
Diffstat (limited to 'nixos/lib/test-driver/test_driver/polling_condition.py')
-rw-r--r-- | nixos/lib/test-driver/test_driver/polling_condition.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/nixos/lib/test-driver/test_driver/polling_condition.py b/nixos/lib/test-driver/test_driver/polling_condition.py index fe064b1f830..65b00114336 100644 --- a/nixos/lib/test-driver/test_driver/polling_condition.py +++ b/nixos/lib/test-driver/test_driver/polling_condition.py @@ -10,17 +10,6 @@ class PollingConditionFailed(Exception): pass -def coopmulti(fun: Callable) -> Callable: - @wraps(fun) - def wrapper(machine: Any, *args: List[Any], **kwargs: Dict[str, Any]) -> Any: - if machine.fail_early(): # type: ignore - raise PollingConditionFailed("Test interrupted early...") - - return fun(machine, *args, **kwargs) - - return wrapper - - class PollingCondition: condition: Callable[[], bool] seconds_interval: float @@ -39,7 +28,10 @@ class PollingCondition: self.seconds_interval = seconds_interval if description is None: - self.description = condition.__doc__ + if condition.__doc__: + self.description = condition.__doc__ + else: + self.description = condition.__name__ else: self.description = str(description) @@ -57,9 +49,16 @@ class PollingCondition: except Exception: res = False res = res is None or res - rootlog.info(f"Polling condition {'succeeded' if res else 'failed'}") + rootlog.info(self.status_message(res)) return res + def maybe_raise(self) -> None: + if not self.check(): + raise PollingConditionFailed(self.status_message(False)) + + def status_message(self, status: bool) -> str: + return f"Polling condition {'succeeded' if status else 'failed'}: {self.description}" + @property def nested_message(self) -> str: nested_message = ["Checking polling condition"] |