Skip to content

Commit

Permalink
update according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhaoling committed Aug 28, 2020
1 parent a8a0782 commit 71de398
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from typing import Any, List, TYPE_CHECKING
import logging

import uamqp

Expand All @@ -16,6 +17,8 @@
if TYPE_CHECKING:
from azure.core.credentials import TokenCredential

_LOGGER = logging.getLogger(__name__)


class ServiceBusClient(object):
"""The ServiceBusClient class defines a high level interface for
Expand Down Expand Up @@ -96,7 +99,14 @@ def close(self):
:return: None
"""
for handler in self._handlers:
handler.close()
try:
handler.close()
except Exception as exception: # pylint: disable=broad-except
_LOGGER.error(
"Client has met an exception when closing the handler: %r. Exception: %r.",
handler._container_id, # pylint: disable=protected-access
exception,
)
self._handlers.clear()

if self._connection_sharing and self._connection:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from typing import Any, List, TYPE_CHECKING
import logging

import uamqp

Expand All @@ -18,6 +19,8 @@
if TYPE_CHECKING:
from azure.core.credentials import TokenCredential

_LOGGER = logging.getLogger(__name__)


class ServiceBusClient(object):
"""The ServiceBusClient class defines a high level interface for
Expand Down Expand Up @@ -139,7 +142,14 @@ async def close(self):
:return: None
"""
for handler in self._handlers:
await handler.close()
try:
await handler.close()
except Exception as exception: # pylint: disable=broad-except
_LOGGER.error(
"Client has met an exception when closing the handler: %r. Exception: %r.",
handler._container_id, # pylint: disable=protected-access
exception,
)
self._handlers.clear()

if self._connection_sharing and self._connection:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ServiceBusClientAsyncTests(AzureMgmtTestCase):
async def test_async_sb_client_close_spawned_handlers(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
client = ServiceBusClient.from_connection_string(servicebus_namespace_connection_string)

await client.close()

# context manager
async with client:
assert len(client._handlers) == 0
Expand Down
2 changes: 2 additions & 0 deletions sdk/servicebus/azure-servicebus/tests/test_sb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def test_sb_client_incorrect_queue_conn_str(self, servicebus_queue_authorization
def test_sb_client_close_spawned_handlers(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
client = ServiceBusClient.from_connection_string(servicebus_namespace_connection_string)

client.close()

# context manager
with client:
assert len(client._handlers) == 0
Expand Down

0 comments on commit 71de398

Please sign in to comment.