Skip to content

Commit d660c37

Browse files
authored
Fix Prefect flaky test (DataDog#23219)
* Add Waitfor for tasks * Add timeout * Increase window between runs * Reduce timeout
1 parent 33e191a commit d660c37

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

prefect/tests/conftest.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from typing import Callable
88

99
import pytest
10+
import requests
1011

11-
from datadog_checks.dev.conditions import CheckDockerLogs, CheckEndpoints
12+
from datadog_checks.dev.conditions import CheckDockerLogs, CheckEndpoints, WaitFor
1213
from datadog_checks.dev.docker import docker_run, get_docker_hostname
1314
from datadog_checks.dev.utils import find_free_port
1415
from datadog_checks.prefect import PrefectCheck
@@ -20,6 +21,23 @@
2021
}
2122

2223

24+
def _check_task_runs_available(prefect_url: str):
25+
"""Verify that the Prefect API has task runs and task-run events queryable."""
26+
resp = requests.post(f"{prefect_url}/task_runs/filter", json={}, timeout=1)
27+
resp.raise_for_status()
28+
task_runs = resp.json()
29+
assert task_runs, "No task runs available in Prefect API yet"
30+
31+
resp = requests.post(
32+
f"{prefect_url}/events/filter",
33+
json={"filter": {"event": {"prefix": ["prefect.task-run"]}}},
34+
timeout=1,
35+
)
36+
resp.raise_for_status()
37+
events = resp.json().get("events", [])
38+
assert events, "No task-run events available in Prefect API yet"
39+
40+
2341
@pytest.fixture(scope='session')
2442
def dd_environment(instance: Callable[[str], dict[str, str | dict[str, list[str]] | None | bool | int]]):
2543
port = find_free_port(get_docker_hostname())
@@ -35,6 +53,7 @@ def dd_environment(instance: Callable[[str], dict[str, str | dict[str, list[str]
3553
COMPOSE_FILE_E2E, patterns=["Finished all tasks"], service="prefect-worker", attempts=120, wait=1
3654
),
3755
CheckDockerLogs(COMPOSE_FILE_E2E, patterns=["Retried"], service="prefect-worker", attempts=120, wait=1),
56+
WaitFor(lambda: _check_task_runs_available(prefect_url), attempts=60, wait=2),
3857
]
3958

4059
with docker_run(

prefect/tests/test_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
@pytest.mark.e2e
8585
def test_e2e_metrics(dd_agent_check):
86-
aggregator = dd_agent_check()
86+
aggregator = dd_agent_check(check_times=2, pause=20000)
8787

8888
cross_check_metrics = (
8989
'flow_runs.retry_gaps_duration',

0 commit comments

Comments
 (0)