From 94ee457f576b61fed7babcb525d041ce8c14a455 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 09:31:26 +0000 Subject: [PATCH 1/2] Initial plan From 2900cf5e9ff16300e75d7030e59e6a780e31024c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 09:35:09 +0000 Subject: [PATCH 2/2] fix: make test_collect_resets_start_time_unix_nano deterministic on PyPy/Windows Replace real time_ns() calls inside the test body with fixed literal values. The test patches the module-level time_ns but was still calling the real time_ns() from `from time import time_ns`, mixing mocked and real clock values which caused nondeterminism on Windows/PyPy. Assisted-by: Claude Opus 4.6 Agent-Logs-Url: https://github.com/open-telemetry/opentelemetry-python/sessions/90d2ba7b-9d8d-428d-bc85-e0631ee832ec Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com> --- .../metrics/test_view_instrument_match.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py index 38d36758f39..bda1cd3dfe3 100644 --- a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py +++ b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py @@ -291,7 +291,7 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns): view_instrument_match.consume_measurement( Measurement( value=0, - time_unix_nano=time_ns(), + time_unix_nano=123, instrument=instrument, attributes={"foo": "bar0"}, context=Context(), @@ -303,9 +303,8 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns): _default_reservoir_factory, start_time_unix_nano, ) - collection_start_time_unix_nano = time_ns() collected_data_points = view_instrument_match.collect( - AggregationTemporality.CUMULATIVE, collection_start_time_unix_nano + AggregationTemporality.CUMULATIVE, 456 ) self.assertIsNotNone(collected_data_points) self.assertEqual(len(collected_data_points), 1) @@ -314,7 +313,7 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns): view_instrument_match.consume_measurement( Measurement( value=0, - time_unix_nano=time_ns(), + time_unix_nano=789, instrument=instrument, attributes={"foo": "bar1"}, context=Context(), @@ -323,20 +322,19 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns): view_instrument_match._view._aggregation._create_aggregation.assert_called_with( instrument, {"foo": "bar1"}, _default_reservoir_factory, 1 ) - collection_start_time_unix_nano = time_ns() collected_data_points = view_instrument_match.collect( - AggregationTemporality.CUMULATIVE, collection_start_time_unix_nano + AggregationTemporality.CUMULATIVE, 999 ) self.assertIsNotNone(collected_data_points) self.assertEqual(len(collected_data_points), 2) collected_data_points = view_instrument_match.collect( - AggregationTemporality.CUMULATIVE, collection_start_time_unix_nano + AggregationTemporality.CUMULATIVE, 999 ) # +1 call to create_aggregation view_instrument_match.consume_measurement( Measurement( value=0, - time_unix_nano=time_ns(), + time_unix_nano=1000, instrument=instrument, attributes={"foo": "bar"}, context=Context(), @@ -349,7 +347,7 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns): view_instrument_match.consume_measurement( Measurement( value=0, - time_unix_nano=time_ns(), + time_unix_nano=1001, instrument=instrument, attributes={"foo": "bar"}, context=Context(), @@ -358,7 +356,7 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns): view_instrument_match.consume_measurement( Measurement( value=0, - time_unix_nano=time_ns(), + time_unix_nano=1002, instrument=instrument, attributes={"foo": "bar"}, context=Context(),