ashb commented on code in PR #77877:
URL: https://github.com/apache/airflow/pull/77877#discussion_r4770012288


##########
task-sdk/tests/task_sdk/execution_time/test_timeout.py:
##########
@@ -75,3 +77,64 @@ def test_timeout_happens(self):
         tp = TimeoutPosix(seconds=1, error_message="boom")
         with pytest.raises(AirflowTaskTimeout, match="boom"):
             tp.handle_timeout(signal.SIGALRM, None)
+
+    def 
test_timeout_is_logged_once_the_block_is_left_not_by_the_signal_handler(self):
+        """
+        The handler runs wherever the main thread is, possibly inside the lock 
of the log output:
+        logging there would wait for that lock forever. The timeout is logged 
when the block exits.
+        """
+        if not hasattr(signal, "SIGALRM"):
+            pytest.skip("SIGALRM not supported on this platform")
+
+        held_by_the_main_thread = threading.Lock()
+        locked_when_logged = []
+        tp = TimeoutPosix(seconds=60, error_message="boom")
+        tp.log = mock.Mock(spec=structlog.stdlib.BoundLogger)
+        tp.log.error.side_effect = lambda *args, **kwargs: 
locked_when_logged.append(
+            held_by_the_main_thread.locked()
+        )
+
+        def time_out_inside_the_lock():
+            with tp, held_by_the_main_thread:
+                signal.raise_signal(signal.SIGALRM)
+
+        with pytest.raises(AirflowTaskTimeout, match="boom"):
+            time_out_inside_the_lock()
+
+        assert locked_when_logged == [False]
+        tp.log.error.assert_called_once_with("Process timed out", pid=mock.ANY)
+
+    def test_nothing_is_logged_when_the_block_ends_in_time(self):
+        if not hasattr(signal, "SIGALRM"):
+            pytest.skip("SIGALRM not supported on this platform")
+
+        tp = TimeoutPosix(seconds=60)
+        tp.log = mock.Mock(spec=structlog.stdlib.BoundLogger)

Review Comment:
   I'd rather we used real structlog objects and the existing log capture 
fixtures if we can



##########
task-sdk/tests/task_sdk/execution_time/test_timeout.py:
##########
@@ -75,3 +77,64 @@ def test_timeout_happens(self):
         tp = TimeoutPosix(seconds=1, error_message="boom")
         with pytest.raises(AirflowTaskTimeout, match="boom"):
             tp.handle_timeout(signal.SIGALRM, None)
+
+    def 
test_timeout_is_logged_once_the_block_is_left_not_by_the_signal_handler(self):
+        """
+        The handler runs wherever the main thread is, possibly inside the lock 
of the log output:
+        logging there would wait for that lock forever. The timeout is logged 
when the block exits.
+        """
+        if not hasattr(signal, "SIGALRM"):
+            pytest.skip("SIGALRM not supported on this platform")
+
+        held_by_the_main_thread = threading.Lock()
+        locked_when_logged = []
+        tp = TimeoutPosix(seconds=60, error_message="boom")
+        tp.log = mock.Mock(spec=structlog.stdlib.BoundLogger)
+        tp.log.error.side_effect = lambda *args, **kwargs: 
locked_when_logged.append(
+            held_by_the_main_thread.locked()
+        )
+
+        def time_out_inside_the_lock():
+            with tp, held_by_the_main_thread:
+                signal.raise_signal(signal.SIGALRM)
+
+        with pytest.raises(AirflowTaskTimeout, match="boom"):
+            time_out_inside_the_lock()
+
+        assert locked_when_logged == [False]
+        tp.log.error.assert_called_once_with("Process timed out", pid=mock.ANY)
+
+    def test_nothing_is_logged_when_the_block_ends_in_time(self):
+        if not hasattr(signal, "SIGALRM"):
+            pytest.skip("SIGALRM not supported on this platform")

Review Comment:
   Skipif decorator instead? 



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