kaxil commented on code in PR #44626:
URL: https://github.com/apache/airflow/pull/44626#discussion_r1875668467


##########
task_sdk/tests/execution_time/test_supervisor.py:
##########
@@ -179,6 +179,31 @@ def subprocess_main():
 
         assert rc == -9
 
+    def test_supervisor_signal_handling(self, mocker):
+        """Verify that the supervisor correctly handles signals and terminates 
the task process."""
+        mock_logger = mocker.patch("airflow.sdk.execution_time.supervisor.log")
+        mock_kill = 
mocker.patch("airflow.sdk.execution_time.supervisor.WatchedSubprocess.kill")
+
+        proc = WatchedSubprocess(
+            ti_id=TI_ID, pid=12345, stdin=mocker.Mock(), 
process=mocker.Mock(), client=mocker.Mock()
+        )
+
+        # Send a SIGTERM signal to the supervisor
+        proc._setup_signal_handlers()
+        os.kill(os.getpid(), signal.SIGTERM)
+
+        # Verify task process termination and log messages
+        # Asserting that `proc.kill` is called with the correct signal is 
sufficient to verify the supervisor
+        # correctly handles the signal and terminates the task process
+        # The actual signal sent to the task process is tested in 
`TestWatchedSubprocessKill` class
+        mock_kill.assert_called_once_with(signal.SIGTERM, force=True)
+        mock_logger.error.assert_called_once_with(
+            "Received termination signal in supervisor. Terminating watched 
subprocess",

Review Comment:
   I should probably also assert that a final TI patch was called, 🤔 



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