uranusjr commented on code in PR #70671:
URL: https://github.com/apache/airflow/pull/70671#discussion_r4397662126


##########
airflow-core/tests/unit/utils/test_log_handlers.py:
##########
@@ -502,10 +518,75 @@ def test__read_when_local_respects_log_pos_metadata(self, 
mock_read_local, creat
 
         # Should resume from the third line only.
         assert extract_events(log_handler_output_stream) == ["line 3"]
-        assert metadata == {"end_of_log": True, "log_pos": 3}
+        assert metadata == {"end_of_log": True}
+
+    @pytest.mark.parametrize(
+        ("ti_state", "ti_try_number", "expected_metadata"),
+        [
+            pytest.param(
+                TaskInstanceState.RUNNING,
+                1,
+                {"end_of_log": False, "log_pos": 3},
+                id="running-current-try",
+            ),
+            pytest.param(
+                TaskInstanceState.DEFERRED,
+                1,
+                {"end_of_log": False, "log_pos": 3},
+                id="deferred-current-try",
+            ),
+            pytest.param(TaskInstanceState.RUNNING, 2, {"end_of_log": True}, 
id="running-older-try"),
+            pytest.param(TaskInstanceState.SUCCESS, 1, {"end_of_log": True}, 
id="success"),
+            pytest.param(TaskInstanceState.FAILED, 1, {"end_of_log": True}, 
id="failed"),
+        ],
+    )
+    def test__read_accumulates_only_unfinished_reads(
+        self, ti_state, ti_try_number, expected_metadata, create_task_instance
+    ):
+        ti = create_task_instance(
+            dag_id="dag_for_testing_local_log_read",
+            task_id="task_for_testing_local_log_read",
+            run_type=DagRunType.SCHEDULED,
+            logical_date=DEFAULT_DATE,
+            state=ti_state,
+        )
+        ti.try_number = ti_try_number
+        source, pulled = _tracking_stream(["line 1", "line 2", "line 3"])
+        fth = FileTaskHandler("")
 
+        with (
+            patch.object(fth, "_read_from_local", return_value=(["the 
messages"], [source])),
+            patch.object(fth, "_read_from_logs_server", return_value=([], [])),
+            patch.object(fth, "_get_executor") as get_executor,
+            patch(
+                "airflow.utils.log.file_task_handler.LogStreamAccumulator", 
wraps=LogStreamAccumulator
+            ) as accumulator,
+        ):
+            get_executor.return_value.get_streaming_task_log.return_value = 
([], [])
+            log_handler_output_stream, metadata = fth._read(ti=ti, 
try_number=1)
+
+            accumulated = not expected_metadata["end_of_log"]
+            # An unfinished read drains the source up front to count lines; a 
finished read stays lazy.

Review Comment:
   ```suggestion
   ```



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