You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by vi...@apache.org on 2023/11/03 13:55:45 UTC

(airflow) branch main updated: Add more unit test to cover debug executor (#35400)

This is an automated email from the ASF dual-hosted git repository.

vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 3d23bf9dba Add more unit test to cover debug executor (#35400)
3d23bf9dba is described below

commit 3d23bf9dbad6266dd99431a93cf29e886fab974a
Author: Owen Leung <ow...@gmail.com>
AuthorDate: Fri Nov 3 21:55:38 2023 +0800

    Add more unit test to cover debug executor (#35400)
---
 scripts/cov/core_coverage.py           |  1 -
 tests/executors/test_debug_executor.py | 24 ++++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/scripts/cov/core_coverage.py b/scripts/cov/core_coverage.py
index 38d001d2db..f5d2c88f28 100644
--- a/scripts/cov/core_coverage.py
+++ b/scripts/cov/core_coverage.py
@@ -35,7 +35,6 @@ source_files = [
 
 files_not_fully_covered = [
     # executors
-    "airflow/executors/debug_executor.py",
     "airflow/executors/executor_loader.py",
     "airflow/executors/local_executor.py",
     "airflow/executors/sequential_executor.py",
diff --git a/tests/executors/test_debug_executor.py b/tests/executors/test_debug_executor.py
index 0cc82d3021..03a91f9c92 100644
--- a/tests/executors/test_debug_executor.py
+++ b/tests/executors/test_debug_executor.py
@@ -124,3 +124,27 @@ class TestDebugExecutor:
 
     def test_is_production_default_value(self):
         assert not DebugExecutor.is_production
+
+    @mock.patch("time.sleep", autospec=True)
+    def test_trigger_sleep_when_no_task(self, mock_sleep):
+        execute_mock = MagicMock()
+        executor = DebugExecutor()
+        executor.execute_async = execute_mock
+        executor.queued_tasks = {}
+        executor.trigger_tasks(open_slots=5)
+        mock_sleep.assert_called()
+
+    @mock.patch("airflow.executors.debug_executor.DebugExecutor.change_state")
+    def test_sync_after_terminate(self, change_state_mock):
+        executor = DebugExecutor()
+
+        ti1 = MagicMock(key="t1")
+        executor.tasks_to_run = [ti1]
+        executor.terminate()
+        executor.sync()
+
+        change_state_mock.assert_has_calls(
+            [
+                mock.call(ti1.key, State.FAILED),
+            ]
+        )