Skip to content

Commit

Permalink
[ServiceBus] Improve test stability and cpu usage (#20352)
Browse files Browse the repository at this point in the history
* updatet test and improve cpu usage

* update changelog
  • Loading branch information
yunhaoling authored Aug 30, 2021
1 parent fac427d commit 0320ace
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Other Changes

- Reduced CPU load of `azure.servicebus.AutoLockRenewer` during lock renewal.

## 7.3.2 (2021-08-10)

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions sdk/servicebus/azure-servicebus/tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions sdk/servicebus/azure-servicebus/tests/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,8 +1597,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

Expand Down

0 comments on commit 0320ace

Please sign in to comment.