From e4a36e2adab1e59c9706173af22f4aae3975c6b7 Mon Sep 17 00:00:00 2001 From: "Adam Ling (MSFT)" Date: Wed, 18 Aug 2021 21:41:37 -0700 Subject: [PATCH 1/2] updatet test and improve cpu usage --- .../azure/servicebus/_common/auto_lock_renewer.py | 1 + sdk/servicebus/azure-servicebus/tests/mocks.py | 4 ++-- sdk/servicebus/azure-servicebus/tests/test_queues.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/auto_lock_renewer.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/auto_lock_renewer.py index c714aad6b4b0..ecf3074c7a14 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/auto_lock_renewer.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/auto_lock_renewer.py @@ -176,6 +176,7 @@ def _dispatch_worker(self): self._running_dispatcher.clear() self._last_activity_timestamp = None return + time.sleep(self._sleep_time) # save cpu cycles if there's currently no task in self._renew_tasks def _auto_lock_renew_task( self, diff --git a/sdk/servicebus/azure-servicebus/tests/mocks.py b/sdk/servicebus/azure-servicebus/tests/mocks.py index 67d81d704058..00c5a63dc9ac 100644 --- a/sdk/servicebus/azure-servicebus/tests/mocks.py +++ b/sdk/servicebus/azure-servicebus/tests/mocks.py @@ -16,8 +16,8 @@ def renew_message_lock(self, message): class MockReceivedMessage(ServiceBusReceivedMessage): - def __init__(self, prevent_renew_lock=False, exception_on_renew_lock=False): - self._lock_duration = 2 + def __init__(self, prevent_renew_lock=False, exception_on_renew_lock=False, **kwargs): + self._lock_duration = kwargs.get("lock_duration", 2) self._raw_amqp_message = None self._received_timestamp_utc = utc_now() self.locked_until_utc = self._received_timestamp_utc + timedelta(seconds=self._lock_duration) diff --git a/sdk/servicebus/azure-servicebus/tests/test_queues.py b/sdk/servicebus/azure-servicebus/tests/test_queues.py index e77012d58070..5323b1c0b3a8 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_queues.py +++ b/sdk/servicebus/azure-servicebus/tests/test_queues.py @@ -1595,8 +1595,8 @@ def callback_mock(renewable, error): auto_lock_renew = AutoLockRenewer() auto_lock_renew._renew_period = 1 with auto_lock_renew: # Check that in normal operation it does not get called - auto_lock_renew.register(receiver, renewable=MockReceivedMessage(), on_lock_renew_failure=callback_mock) - time.sleep(3) + auto_lock_renew.register(receiver, renewable=MockReceivedMessage(lock_duration=5), on_lock_renew_failure=callback_mock) + time.sleep(6) assert not results assert not errors From 8e9454399badb74121d992c921b6668385cb46c9 Mon Sep 17 00:00:00 2001 From: "Adam Ling (MSFT)" Date: Thu, 19 Aug 2021 11:48:34 -0700 Subject: [PATCH 2/2] update changelog --- sdk/servicebus/azure-servicebus/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/servicebus/azure-servicebus/CHANGELOG.md b/sdk/servicebus/azure-servicebus/CHANGELOG.md index 95a90fd0783e..37acf091c94e 100644 --- a/sdk/servicebus/azure-servicebus/CHANGELOG.md +++ b/sdk/servicebus/azure-servicebus/CHANGELOG.md @@ -10,6 +10,8 @@ ### Other Changes +- Reduced CPU load of `azure.servicebus.AutoLockRenewer` during lock renewal. + ## 7.3.2 (2021-08-10) ### Bugs Fixed