SameerMesiah97 commented on code in PR #73684:
URL: https://github.com/apache/airflow/pull/73684#discussion_r4098727012
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_job.py:
##########
@@ -222,6 +224,38 @@ def test_get_jobs_includes_team_names_and_bundle_names(
assert response_json["jobs"][0]["team_names"] ==
sorted([testing_team.name, extra_team.name])
assert response_json["jobs"][0]["bundle_names"] == ["bundle-a",
"bundle-b"]
+ @time_machine.travel(datetime(2024, 1, 1, tzinfo=timezone.utc), tick=False)
+ def test_get_jobs_is_alive_filter_is_consistent_with_pagination(self,
test_client, session: Session):
+ clear_db_jobs()
+ now = datetime(2024, 1, 1, tzinfo=timezone.utc)
+ session.add_all(
+ [
+ Job(state=JobState.RUNNING, job_type="SchedulerJob",
latest_heartbeat=now),
+ Job(state=JobState.RUNNING, job_type="SchedulerJob",
latest_heartbeat=now),
+ # RUNNING but the heartbeat is older than the health-check
threshold -> not alive.
+ Job(
+ state=JobState.RUNNING,
+ job_type="SchedulerJob",
+ latest_heartbeat=now - timedelta(days=1),
+ ),
+ # Not RUNNING -> not alive.
+ Job(state=JobState.FAILED, job_type="SchedulerJob",
latest_heartbeat=now),
+ ]
+ )
+ session.commit()
+
+ alive = test_client.get("/jobs", params={"is_alive": True}).json()
+ assert alive["total_entries"] == 2
+ assert {job["state"] for job in alive["jobs"]} == {JobState.RUNNING}
+
+ not_alive = test_client.get("/jobs", params={"is_alive": False}).json()
+ assert not_alive["total_entries"] == 2
Review Comment:
It looks like you are checking the count for the dead job but not the jobs
themselves. Please see the below for inspiration:
```
jobs = [
Job(state=JobState.RUNNING, job_type="SchedulerJob",
latest_heartbeat=now),
Job(state=JobState.RUNNING, job_type="SchedulerJob",
latest_heartbeat=now),
Job(state=JobState.RUNNING, job_type="SchedulerJob",
latest_heartbeat=now - timedelta(days=1)),
Job(state=JobState.FAILED, job_type="SchedulerJob",
latest_heartbeat=now),
]
session.add_all(jobs)
session.commit()
assert {job["id"] for job in not_alive["jobs"]} == {jobs[2].id, jobs[3].id}
```
basically add the jobs and then cross-ref the IDs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]