nixos/test-driver: rewrite wait_before_entry to wait
This commit is contained in:
parent
2a3834b7eb
commit
976f00963f
|
@ -202,7 +202,6 @@ class Driver:
|
||||||
*,
|
*,
|
||||||
seconds_interval: float = 2.0,
|
seconds_interval: float = 2.0,
|
||||||
description: Optional[str] = None,
|
description: Optional[str] = None,
|
||||||
wait_before_entry: bool = False,
|
|
||||||
) -> Union[Callable[[Callable], ContextManager], ContextManager]:
|
) -> Union[Callable[[Callable], ContextManager], ContextManager]:
|
||||||
driver = self
|
driver = self
|
||||||
|
|
||||||
|
@ -213,21 +212,28 @@ class Driver:
|
||||||
seconds_interval,
|
seconds_interval,
|
||||||
description,
|
description,
|
||||||
)
|
)
|
||||||
self.wait_before_entry = wait_before_entry
|
|
||||||
|
|
||||||
def __enter__(self) -> None:
|
def __enter__(self) -> None:
|
||||||
if self.wait_before_entry:
|
|
||||||
with rootlog.nested(
|
|
||||||
f"waiting before entering polling condition {self.condition.description}"
|
|
||||||
):
|
|
||||||
retry(lambda x: self.condition.check(force=True))
|
|
||||||
|
|
||||||
driver.polling_conditions.append(self.condition)
|
driver.polling_conditions.append(self.condition)
|
||||||
|
|
||||||
def __exit__(self, a, b, c) -> None: # type: ignore
|
def __exit__(self, a, b, c) -> None: # type: ignore
|
||||||
res = driver.polling_conditions.pop()
|
res = driver.polling_conditions.pop()
|
||||||
assert res is self.condition
|
assert res is self.condition
|
||||||
|
|
||||||
|
def wait(self, timeout: int = 900) -> None:
|
||||||
|
def condition(last: bool) -> bool:
|
||||||
|
if last:
|
||||||
|
rootlog.info(f"Last chance for {self.condition.description}")
|
||||||
|
ret = self.condition.check(force=True)
|
||||||
|
if not ret and not last:
|
||||||
|
rootlog.info(
|
||||||
|
f"({self.condition.description} failure not fatal yet)"
|
||||||
|
)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
with rootlog.nested(f"waiting for {self.condition.description}"):
|
||||||
|
retry(condition, timeout=timeout)
|
||||||
|
|
||||||
if fun_ is None:
|
if fun_ is None:
|
||||||
return Poll
|
return Poll
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -33,7 +33,7 @@ let
|
||||||
};
|
};
|
||||||
enableOCR = true;
|
enableOCR = true;
|
||||||
testScript = ''
|
testScript = ''
|
||||||
@polling_condition(wait_before_entry=True)
|
@polling_condition
|
||||||
def codium_running():
|
def codium_running():
|
||||||
machine.succeed('pgrep -x codium')
|
machine.succeed('pgrep -x codium')
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ let
|
||||||
|
|
||||||
machine.wait_for_unit('graphical.target')
|
machine.wait_for_unit('graphical.target')
|
||||||
|
|
||||||
|
codium_running.wait()
|
||||||
with codium_running:
|
with codium_running:
|
||||||
# Wait until vscodium is visible. "File" is in the menu bar.
|
# Wait until vscodium is visible. "File" is in the menu bar.
|
||||||
machine.wait_for_text('Get Started')
|
machine.wait_for_text('Get Started')
|
||||||
|
|
Loading…
Reference in a new issue