x
This commit is contained in:
+3
-3
@@ -27,14 +27,14 @@ class EventuallyFn(Protocol):
|
||||
def __call__(
|
||||
self,
|
||||
assert_fn: Callable[[], bool],
|
||||
timeout: float = 2.0,
|
||||
interval: float = 0.05,
|
||||
timeout: float = 5.0,
|
||||
interval: float = 0.5,
|
||||
) -> None: ...
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def eventually() -> EventuallyFn:
|
||||
def _eventually(assert_fn: Callable[[], bool], timeout: float = 2.0, interval: float = 0.05) -> None:
|
||||
def _eventually(assert_fn: Callable[[], bool], timeout: float = 5.0, interval: float = 0.5) -> None:
|
||||
deadline = time.monotonic() + timeout
|
||||
last_error: BaseException | None = None
|
||||
while time.monotonic() < deadline:
|
||||
|
||||
@@ -46,6 +46,51 @@ class BrencherPage:
|
||||
timeout=10000,
|
||||
)
|
||||
|
||||
def verify_pipeline_step_status(self, step_name: str, expected_status: str, timeout_ms: int = 10000) -> None:
|
||||
"""
|
||||
Verify that a pipeline step reaches the expected status by polling the page DOM.
|
||||
|
||||
Args:
|
||||
step_name: Name of the pipeline step (e.g., "DockerContainerDeploy")
|
||||
expected_status: Expected status value ("running", "ok", "error", or "dry-run")
|
||||
timeout_ms: Timeout in milliseconds (default 10000)
|
||||
"""
|
||||
# JavaScript to check pipeline step status
|
||||
js_check = """(stepName, expectedStatus) => {
|
||||
const jobItems = document.querySelectorAll('.job-item');
|
||||
for (const item of jobItems) {
|
||||
const headerText = item.querySelector('.job-header')?.textContent || '';
|
||||
if (headerText.includes(stepName)) {
|
||||
const spinner = item.querySelector('.step-spinner');
|
||||
const errorIndicator = item.querySelector('span[title="Error"]');
|
||||
|
||||
if (expectedStatus === 'running') {
|
||||
return spinner !== null;
|
||||
} else if (expectedStatus === 'ok') {
|
||||
return spinner === null && errorIndicator === null;
|
||||
} else if (expectedStatus === 'error') {
|
||||
return errorIndicator !== null;
|
||||
} else if (expectedStatus === 'dry-run') {
|
||||
// For dry-run, check the spoiler content
|
||||
const spoiler = item.querySelector('.job-spoiler');
|
||||
if (spoiler && spoiler.style.display !== 'none') {
|
||||
const statusText = spoiler.textContent;
|
||||
return statusText.includes('dry-run') || statusText.includes('dry_run');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}"""
|
||||
|
||||
self._page.wait_for_function(
|
||||
js_check,
|
||||
arg=[step_name, expected_status],
|
||||
timeout=timeout_ms,
|
||||
)
|
||||
self._logger.info(f"Pipeline step '{step_name}' reached status '{expected_status}'")
|
||||
|
||||
|
||||
@contextmanager
|
||||
def brencher_page(
|
||||
|
||||
@@ -46,44 +46,39 @@ class TestDryRunPlaywright:
|
||||
server_thread.start()
|
||||
|
||||
# Wait for server to be up
|
||||
eventually(
|
||||
lambda: requests.get(f"{APP_URL}/state", timeout=5).status_code == 200,
|
||||
timeout=20.0,
|
||||
interval=1.0,
|
||||
)
|
||||
eventually(lambda: requests.get(f"{APP_URL}/state", timeout=5).status_code == 200)
|
||||
logger.info("Server is up")
|
||||
|
||||
# Wait for the pipeline to stabilize with dry=True:
|
||||
# DockerContainerDeploy should return status="dry-run"
|
||||
eventually(
|
||||
lambda: _check_state(APP_URL, lambda s: next(
|
||||
p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy"
|
||||
)["status"].get("status") == "dry-run"),
|
||||
timeout=10.0,
|
||||
interval=2.0,
|
||||
)
|
||||
logger.info("Pipeline is in dry-run mode")
|
||||
|
||||
# Verify no real container was created
|
||||
docker_client = docker.from_env()
|
||||
real_containers = docker_client.containers.list(filters={"name": CONTAINER_NAME}, all=True)
|
||||
assert len(real_containers) == 0, "Container should NOT exist during dry run"
|
||||
|
||||
# Open browser and disable dry run from the UI.
|
||||
with brencher_page(APP_URL) as page:
|
||||
eventually(
|
||||
lambda: _check_state(APP_URL, lambda s: next(
|
||||
p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy"
|
||||
)["status"].get("status") == "dry-run"),
|
||||
)
|
||||
|
||||
# page.verify_pipeline_step_status("DockerContainerDeploy", "dry-run")
|
||||
logger.info("Pipeline is in dry-run mode")
|
||||
|
||||
# Verify no real container was created
|
||||
docker_client = docker.from_env()
|
||||
real_containers = docker_client.containers.list(filters={"name": CONTAINER_NAME}, all=True)
|
||||
assert len(real_containers) == 0, "Container should NOT exist during dry run"
|
||||
|
||||
# Disable dry run from the UI.
|
||||
page.verify_dry_run_on()
|
||||
page.set_dry_run_off()
|
||||
page.verify_dry_run_off()
|
||||
page.click_refresh()
|
||||
page.click_refresh() # TODO Remove it
|
||||
|
||||
# Wait for pipeline to re-run and actually deploy the container
|
||||
eventually(
|
||||
lambda: _check_state(APP_URL, lambda s: next(
|
||||
p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy"
|
||||
)["status"].get("status") == "running"),
|
||||
timeout=10.0,
|
||||
interval=2.0,
|
||||
)
|
||||
# Wait for pipeline to re-run and actually deploy the container
|
||||
eventually(
|
||||
lambda: _check_state(APP_URL, lambda s: next(
|
||||
p for p in s[ENV_ID]["pipeline"] if p["name"] == "DockerContainerDeploy"
|
||||
)["status"].get("status") == "running"),
|
||||
)
|
||||
# page.verify_pipeline_step_status("DockerContainerDeploy", "running")
|
||||
logger.info("Container deployed and running after dry run disabled")
|
||||
|
||||
# Final sanity: real container must exist and be running
|
||||
|
||||
Reference in New Issue
Block a user