mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-14 05:29:20 +03:00
Merge pull request #170636 from Synthetica9/wait_before_entry
nixos/test-driver: add wait_before_entry
This commit is contained in:
commit
9938dec682
3 changed files with 37 additions and 8 deletions
|
@ -220,6 +220,20 @@ class Driver:
|
||||||
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:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
|
from math import isfinite
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from .logger import rootlog
|
from .logger import rootlog
|
||||||
|
@ -14,7 +15,7 @@ class PollingCondition:
|
||||||
description: Optional[str]
|
description: Optional[str]
|
||||||
|
|
||||||
last_called: float
|
last_called: float
|
||||||
entered: bool
|
entry_count: int
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -34,14 +35,21 @@ class PollingCondition:
|
||||||
self.description = str(description)
|
self.description = str(description)
|
||||||
|
|
||||||
self.last_called = float("-inf")
|
self.last_called = float("-inf")
|
||||||
self.entered = False
|
self.entry_count = 0
|
||||||
|
|
||||||
def check(self) -> bool:
|
def check(self, force: bool = False) -> bool:
|
||||||
if self.entered or not self.overdue:
|
if (self.entered or not self.overdue) and not force:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
with self, rootlog.nested(self.nested_message):
|
with self, rootlog.nested(self.nested_message):
|
||||||
rootlog.info(f"Time since last: {time.monotonic() - self.last_called:.2f}s")
|
time_since_last = time.monotonic() - self.last_called
|
||||||
|
last_message = (
|
||||||
|
f"Time since last: {time_since_last:.2f}s"
|
||||||
|
if isfinite(time_since_last)
|
||||||
|
else "(not called yet)"
|
||||||
|
)
|
||||||
|
|
||||||
|
rootlog.info(last_message)
|
||||||
try:
|
try:
|
||||||
res = self.condition() # type: ignore
|
res = self.condition() # type: ignore
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -69,9 +77,16 @@ class PollingCondition:
|
||||||
def overdue(self) -> bool:
|
def overdue(self) -> bool:
|
||||||
return self.last_called + self.seconds_interval < time.monotonic()
|
return self.last_called + self.seconds_interval < time.monotonic()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def entered(self) -> bool:
|
||||||
|
# entry_count should never dip *below* zero
|
||||||
|
assert self.entry_count >= 0
|
||||||
|
return self.entry_count > 0
|
||||||
|
|
||||||
def __enter__(self) -> None:
|
def __enter__(self) -> None:
|
||||||
self.entered = True
|
self.entry_count += 1
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback) -> None: # type: ignore
|
def __exit__(self, exc_type, exc_value, traceback) -> None: # type: ignore
|
||||||
self.entered = False
|
assert self.entered
|
||||||
|
self.entry_count -= 1
|
||||||
self.last_called = time.monotonic()
|
self.last_called = time.monotonic()
|
||||||
|
|
|
@ -49,8 +49,8 @@ let
|
||||||
start_all()
|
start_all()
|
||||||
|
|
||||||
machine.wait_for_unit('graphical.target')
|
machine.wait_for_unit('graphical.target')
|
||||||
machine.wait_until_succeeds('pgrep -x codium')
|
|
||||||
|
|
||||||
|
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…
Add table
Add a link
Reference in a new issue