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

shahar1 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 6f623854097 Fix flaky AwsTaskLogFetcher tests caused by global 
Event.is_set mock (#68746)
6f623854097 is described below

commit 6f6238540971deecb03f2801f8b834811cda5ca7
Author: PoAn Yang <[email protected]>
AuthorDate: Fri Jun 19 21:31:55 2026 +0900

    Fix flaky AwsTaskLogFetcher tests caused by global Event.is_set mock 
(#68746)
    
    test_run and test_run_with_log_level_detection patch threading.Event.is_set
    at the class level with a fixed, zero-margin side_effect. Because the patch 
is
    global, any other threading.Event in the same process consumes values from 
the
    shared side_effect iterator. When that overlaps the fetcher loop, the
    side_effect is exhausted early and the test fails with StopIteration.
    
    Signed-off-by: PoAn Yang <[email protected]>
---
 .../unit/amazon/aws/utils/test_task_log_fetcher.py     | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git 
a/providers/amazon/tests/unit/amazon/aws/utils/test_task_log_fetcher.py 
b/providers/amazon/tests/unit/amazon/aws/utils/test_task_log_fetcher.py
index 66f883120eb..e1a18faf8d3 100644
--- a/providers/amazon/tests/unit/amazon/aws/utils/test_task_log_fetcher.py
+++ b/providers/amazon/tests/unit/amazon/aws/utils/test_task_log_fetcher.py
@@ -44,10 +44,6 @@ class TestAwsTaskLogFetcher:
     def setup_method(self):
         self.set_up_log_fetcher()
 
-    @mock.patch(
-        "threading.Event.is_set",
-        side_effect=(False, False, False, True),
-    )
     @mock.patch(
         "airflow.providers.amazon.aws.hooks.logs.AwsLogsHook.get_log_events",
         side_effect=(
@@ -65,8 +61,9 @@ class TestAwsTaskLogFetcher:
             iter([]),
         ),
     )
-    def test_run(self, get_log_events_mock, event_is_set_mock):
-        self.log_fetcher.run()
+    def test_run(self, get_log_events_mock):
+        with mock.patch.object(self.log_fetcher._event, "is_set", 
side_effect=(False, False, False, True)):
+            self.log_fetcher.run()
 
         self.logger_mock.log.assert_has_calls(
             [
@@ -146,10 +143,6 @@ class TestAwsTaskLogFetcher:
     def test_get_last_log_messages_with_no_log_events(self, mock_conn):
         assert self.log_fetcher.get_last_log_messages(2) == []
 
-    @mock.patch(
-        "threading.Event.is_set",
-        side_effect=(False, True),
-    )
     @mock.patch(
         "airflow.providers.amazon.aws.hooks.logs.AwsLogsHook.get_log_events",
         side_effect=(
@@ -171,8 +164,9 @@ class TestAwsTaskLogFetcher:
             ),
         ),
     )
-    def test_run_with_log_level_detection(self, get_log_events_mock, 
event_is_set_mock):
-        self.log_fetcher.run()
+    def test_run_with_log_level_detection(self, get_log_events_mock):
+        with mock.patch.object(self.log_fetcher._event, "is_set", 
side_effect=(False, True)):
+            self.log_fetcher.run()
 
         self.logger_mock.log.assert_has_calls(
             [

Reply via email to