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

rom 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 354467ff6a metrics consistancy unit tests update (#42267)
354467ff6a is described below

commit 354467ff6a4c0efd64725c984cffb801a3a4c38a
Author: Gopal Dirisala <[email protected]>
AuthorDate: Tue Sep 17 12:41:38 2024 +0530

    metrics consistancy unit tests update (#42267)
---
 tests/core/test_otel_logger.py | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/tests/core/test_otel_logger.py b/tests/core/test_otel_logger.py
index 9f6ba8ca96..1b0f01c89b 100644
--- a/tests/core/test_otel_logger.py
+++ b/tests/core/test_otel_logger.py
@@ -294,13 +294,21 @@ class TestOtelMetrics:
             name=full_name(name), callbacks=ANY
         )
 
+    @pytest.mark.parametrize(
+        "metrics_consistency_on",
+        [True, False],
+    )
     @mock.patch.object(time, "perf_counter", side_effect=[0.0, 3.14])
-    def test_timer_no_name_returns_float_but_does_not_store_value(self, 
mock_time, name):
+    def test_timer_no_name_returns_float_but_does_not_store_value(
+        self, mock_time, metrics_consistency_on, name
+    ):
+        protocols.metrics_consistency_on = metrics_consistency_on
         with self.stats.timer() as timer:
             pass
 
         assert isinstance(timer.duration, float)
-        assert timer.duration == 3.14
+        expected_duration = 3140.0 if metrics_consistency_on else 3.14
+        assert timer.duration == expected_duration
         assert mock_time.call_count == 2
         self.meter.get_meter().create_observable_gauge.assert_not_called()
 
@@ -326,15 +334,24 @@ class TestOtelMetrics:
         assert mock_time.call_count == 2
         self.meter.get_meter().create_observable_gauge.assert_not_called()
 
+    @pytest.mark.parametrize(
+        "metrics_consistency_on",
+        [
+            True,
+            False,
+        ],
+    )
     @mock.patch.object(time, "perf_counter", side_effect=[0.0, 3.14])
-    def test_timer_start_and_stop_manually_send_true(self, mock_time, name):
+    def test_timer_start_and_stop_manually_send_true(self, mock_time, 
metrics_consistency_on, name):
+        protocols.metrics_consistency_on = metrics_consistency_on
         timer = self.stats.timer(name)
         timer.start()
         # Perform some task
         timer.stop(send=True)
 
         assert isinstance(timer.duration, float)
-        assert timer.duration == 3.14
+        expected_value = 3140.0 if metrics_consistency_on else 3.14
+        assert timer.duration == expected_value
         assert mock_time.call_count == 2
         self.meter.get_meter().create_observable_gauge.assert_called_once_with(
             name=full_name(name), callbacks=ANY

Reply via email to