Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ServiceBus] Improve test stability and cpu usage #20352

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
Copy link
Contributor Author

@yunhaoling yunhaoling Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this test case, 2 seconds would result in random failure on windows, so increasing the time a bit to let AutoLockRenewer to have enough time for renewing work.

also, the minimum allowed lock duration by the service is 5 seconds

time.sleep(6)
assert not results
assert not errors

Expand Down