amoghrajesh commented on code in PR #65232:
URL: https://github.com/apache/airflow/pull/65232#discussion_r3084278884


##########
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py:
##########
@@ -2842,6 +2842,35 @@ def test_write_logs_gives_up_after_max_retries(
         post_complete_action.assert_called_once()
         assert "Reading of logs interrupted with error" in caplog.text
 
+    @patch(KUB_OP_PATH.format("client"))
+    def test_write_logs_with_valid_since_time(self, mocked_client):
+        """Test that since_seconds is calculated correctly when since_time is 
a valid datetime."""
+        pod = k8s.V1Pod(metadata=k8s.V1ObjectMeta(name=TEST_NAME, 
namespace=TEST_NAMESPACE))
+        since_time = datetime.datetime.now(tz=datetime.timezone.utc) - 
datetime.timedelta(seconds=30)
+        k = KubernetesPodOperator(task_id="task", get_logs=True)
+
+        k._write_logs(pod, since_time=since_time)
+
+        _, call_kwargs = mocked_client.read_namespaced_pod_log.call_args
+        assert call_kwargs["since_seconds"] is not None
+        assert call_kwargs["since_seconds"] >= 30

Review Comment:
   Can we use `time_machine` instead of `datetime.datetime.now` instead to have 
some determinism?
   
   Something like:
   
   ```
   @time_machine.travel("2026-01-01 00:00:00", tick=False)
   def test_write_logs_with_valid_since_time(self, mocked_client):
       ...
       since_time = datetime.datetime(2026, 1, 1, 0, 0, 0, 
tzinfo=datetime.timezone.utc) \
                    - datetime.timedelta(seconds=30)
       ....
       k._write_logs(pod, since_time=since_time)
       ....
       assert call_kwargs["since_seconds"] == 30
   ```



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