From ab3be62e52f431f046f17f20c5173d92c3ef84d2 Mon Sep 17 00:00:00 2001 From: "Karen [C] Chen" Date: Tue, 24 Nov 2026 09:17:06 +0000 Subject: [PATCH] fix: limitless monitor property prefix handling --- .../limitless_plugin.py | 3 +- tests/unit/test_limitless_router_monitor.py | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_limitless_router_monitor.py diff --git a/aws_advanced_python_wrapper/limitless_plugin.py b/aws_advanced_python_wrapper/limitless_plugin.py index cf2a708d8..6d78c366d 100644 --- a/aws_advanced_python_wrapper/limitless_plugin.py +++ b/aws_advanced_python_wrapper/limitless_plugin.py @@ -133,7 +133,8 @@ def __init__(self, self._storage_service = services_container.get_storage_service() self._properties = copy.deepcopy(props) - for property_key in self._properties.keys(): + # Iterate over a snapshot: the loop adds and removes keys, which a live keys view does not allow. + for property_key in list(self._properties.keys()): if property_key.startswith(self._MONITORING_PROPERTY_PREFIX): self._properties[property_key[len(self._MONITORING_PROPERTY_PREFIX):]] = self._properties[property_key] self._properties.pop(property_key) diff --git a/tests/unit/test_limitless_router_monitor.py b/tests/unit/test_limitless_router_monitor.py new file mode 100644 index 000000000..5ca1e6dcc --- /dev/null +++ b/tests/unit/test_limitless_router_monitor.py @@ -0,0 +1,37 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from aws_advanced_python_wrapper.hostinfo import HostInfo, HostRole +from aws_advanced_python_wrapper.limitless_plugin import LimitlessRouterMonitor +from aws_advanced_python_wrapper.utils.properties import (Properties, + WrapperProperties) + + +def test_monitor_props_strip_prefix_and_force_no_wait(mocker): + # The constructor starts the monitoring thread; keep it from running so the + # test covers only how the monitoring properties are built. + mocker.patch("aws_advanced_python_wrapper.limitless_plugin.Thread") + mocker.patch("aws_advanced_python_wrapper.limitless_plugin.services_container") + props = Properties({ + "limitless-router-monitor-connect_timeout": "3", + "limitless-router-monitor-socket_timeout": "5", + "limitless_wait_for_transaction_router_info": True, + }) + + monitor = LimitlessRouterMonitor(mocker.MagicMock(), HostInfo("h", 5432, role=HostRole.WRITER), "cache-key", props, 10_000) + + assert monitor._properties.get("connect_timeout") == "3" + assert monitor._properties.get("socket_timeout") == "5" + assert "limitless-router-monitor-connect_timeout" not in monitor._properties + assert "limitless-router-monitor-socket_timeout" not in monitor._properties + assert WrapperProperties.WAIT_FOR_ROUTER_INFO.get(monitor._properties) is False + # The caller's properties are left unchanged. + assert props.get("limitless-router-monitor-connect_timeout") == "3"