77from typing import Callable
88
99import pytest
10+ import requests
1011
11- from datadog_checks .dev .conditions import CheckDockerLogs , CheckEndpoints
12+ from datadog_checks .dev .conditions import CheckDockerLogs , CheckEndpoints , WaitFor
1213from datadog_checks .dev .docker import docker_run , get_docker_hostname
1314from datadog_checks .dev .utils import find_free_port
1415from datadog_checks .prefect import PrefectCheck
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' )
2442def 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 (
0 commit comments