kaxil commented on code in PR #61627:
URL: https://github.com/apache/airflow/pull/61627#discussion_r3307553393
##########
task-sdk/tests/task_sdk/execution_time/test_supervisor.py:
##########
@@ -488,6 +488,61 @@ def on_kill(self) -> None:
captured = capfd.readouterr()
assert "On kill hook called!" in captured.out
+ def test_on_kill_hook_called_when_supervisor_receives_sigterm(
+ self,
+ test_dags_dir,
+ captured_logs,
+ client_with_ti_start,
+ ):
+ """SIGTERM to the supervisor process is forwarded to the task
subprocess.
+
+ Exercises the real ``supervise_task()`` code path: the DAG operator
sends SIGTERM
+ to its parent (the supervisor, which here is this test process running
+ ``supervise_task``). The handler installed inside ``supervise_task``
must forward
+ the signal to the task subprocess so the operator's ``on_kill()`` hook
runs.
+ """
+ import threading
Review Comment:
Nit: hoist `import threading` to the module-top stdlib imports (around line
28) rather than importing it inline inside the test method.
##########
task-sdk/tests/task_sdk/dags/signal_forward_test.py:
##########
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import os
+import signal
+import time
+
+from airflow.sdk.bases.operator import BaseOperator
+from airflow.sdk.definitions.dag import dag
+
+
+class SignalForwardOperator(BaseOperator):
+ """Send SIGTERM to the supervisor parent process to exercise signal
forwarding."""
+
+ def execute(self, context):
+ print("EXECUTE_STARTED", flush=True)
+ os.kill(os.getppid(), signal.SIGTERM)
+ time.sleep(30)
Review Comment:
`time.sleep(30)` makes this test take roughly the full supervisor watchdog
window every run. Per PEP 475, `time.sleep()` resumes after a signal handler
returns, so once `on_kill()` prints its sentinel the call still blocks for the
remainder of the 30s and `execute()` only exits when the watchdog `SIGKILL`s
the child.
Drop this to something short, e.g. `time.sleep(2)`, so the test wall time
matches its real work. The SIGTERM-induced `KeyboardInterrupt` path will exit
`execute()` promptly once the supervisor forwards the signal back.
##########
task-sdk/tests/task_sdk/execution_time/test_supervisor.py:
##########
@@ -488,6 +488,61 @@ def on_kill(self) -> None:
captured = capfd.readouterr()
assert "On kill hook called!" in captured.out
+ def test_on_kill_hook_called_when_supervisor_receives_sigterm(
Review Comment:
Nit: this test drives `supervise_task()` end-to-end (real DAG, real
`parsing_context_manager`, real signal handler), so it organizationally fits
`TestSupervisor` (line 187) better than `TestWatchedSubprocess` where it
currently lives. Not blocking, but worth grouping with the other
`supervise_task` 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]