JoelEmmanuelCloud commented on code in PR #76410:
URL: https://github.com/apache/airflow/pull/76410#discussion_r4671591842


##########
airflow-core/tests/unit/api/common/test_airflow_health.py:
##########
@@ -663,3 +673,330 @@ def 
test_get_airflow_health_mixed_triggerers_include_team_names(self, testing_te
             },
         ]
         assert health_status["triggerer"]["latest_triggerer_heartbeat"] == 
alive_heartbeat.isoformat()
+
+
+# -- Executor health: no configured executor overrides get_health() by 
default, so these tests patch
+# -- _configured_executor_keys directly rather than relying on a real executor 
class, exactly as the
+# -- bundle/team partition tests above patch _configured_bundle_teams.
+
+
+def _executor(
+    *,
+    alive: bool,
+    healthy: bool | None = True,
+    team_name: str | None = None,
+    executor: str | None = None,
+    owner_job_id: int = 1,
+) -> MagicMock:
+    job = _mock_job(
+        hostname=f"host-{owner_job_id}",
+        heartbeat=datetime(2024, 2, 1),
+        alive=alive,
+        team_names=[team_name] if team_name else [],
+    )
+    job.executor_class = executor or f"executor-{team_name}-{'alive' if alive 
else 'stale'}"
+    job.owner_job_id = owner_job_id
+    if healthy is None:
+        job.health_check_result = HealthCheckResult.UNKNOWN
+    else:
+        job.health_check_result = HealthCheckResult.HEALTHY if healthy else 
HealthCheckResult.UNHEALTHY
+    return job
+
+
+def _patch_executor_keys(keys: set[str]):
+    return 
patch("airflow.api.common.airflow_health._configured_executor_keys", 
return_value=keys)
+
+
+def _patch_live_scheduler_ids(ids: set[int]):
+    """Patch which owning-scheduler ids count as alive, standing in for a real 
SchedulerJob query."""
+    return patch("airflow.api.common.airflow_health._live_scheduler_job_ids", 
return_value=ids)
+
+
+class _HealthCheckingExecutor(BaseExecutor):
+    """A stand-in for a concrete executor (e.g. Celery) that has implemented 
get_health()."""
+
+    def get_health(self, timeout: float) -> bool | None:
+        return True
+
+
+class TestConfiguredExecutorKeys:
+    """``_configured_executor_keys`` only counts an executor that actually 
implements get_health()."""
+
+    @pytest.fixture(autouse=True)
+    def clear_executor_caches(self):
+        _configured_executor_keys.cache_clear()
+        _configured_executor_names.cache_clear()
+        yield
+        _configured_executor_keys.cache_clear()
+        _configured_executor_names.cache_clear()
+
+    
@patch("airflow.api.common.airflow_health.ExecutorLoader.get_executor_names")
+    def test_empty_when_no_executor_overrides_get_health(self, 
mock_get_executor_names):
+        mock_get_executor_names.return_value = [
+            
ExecutorName(module_path="airflow.executors.local_executor.LocalExecutor", 
alias="Local")
+        ]
+        assert _configured_executor_keys() == set()
+
+    
@patch("airflow.api.common.airflow_health.ExecutorLoader.import_executor_cls")
+    
@patch("airflow.api.common.airflow_health.ExecutorLoader.get_executor_names")
+    def test_includes_an_executor_that_overrides_get_health(

Review Comment:
   merged both pairs into parametrized tests.



-- 
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]

Reply via email to