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

Fix livetest error and compatibility with EventHub Track1 #78

Merged
merged 6 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
8 changes: 4 additions & 4 deletions samples/asynctests/test_azure_event_hubs_receive_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ async def test_event_hubs_shared_connection_async(live_eventhub_config):
live_eventhub_config['consumer_group'])

async with uamqp.ConnectionAsync(live_eventhub_config['hostname'], sas_auth, debug=False) as conn:
partition_0 = uamqp.ReceiveClientAsync(source + "0", debug=False, auth=sas_auth, timeout=1000, prefetch=1)
partition_1 = uamqp.ReceiveClientAsync(source + "1", debug=False, auth=sas_auth, timeout=1000, prefetch=1)
partition_0 = uamqp.ReceiveClientAsync(source + "0", debug=False, auth=sas_auth, timeout=1000, prefetch=10)
partition_1 = uamqp.ReceiveClientAsync(source + "1", debug=False, auth=sas_auth, timeout=1000, prefetch=10)
await partition_0.open_async(connection=conn)
await partition_1.open_async(connection=conn)
tasks = [
Expand Down Expand Up @@ -181,8 +181,8 @@ async def test_event_hubs_multiple_receiver_async(live_eventhub_config):
live_eventhub_config['event_hub'],
live_eventhub_config['consumer_group'])

partition_0 = uamqp.ReceiveClientAsync(source + "0", debug=False, auth=sas_auth_a, timeout=1000, prefetch=1)
partition_1 = uamqp.ReceiveClientAsync(source + "1", debug=False, auth=sas_auth_b, timeout=1000, prefetch=1)
partition_0 = uamqp.ReceiveClientAsync(source + "0", debug=False, auth=sas_auth_a, timeout=1000, prefetch=10)
partition_1 = uamqp.ReceiveClientAsync(source + "1", debug=False, auth=sas_auth_b, timeout=1000, prefetch=10)
try:
await partition_0.open_async()
await partition_1.open_async()
Expand Down
2 changes: 1 addition & 1 deletion samples/asynctests/test_azure_iothub_cli_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_logger(level):


DEBUG = True
logger = get_logger(logging.WARNING)
logger = get_logger(logging.INFO)


def _generate_sas_token(uri, policy, key, expiry=None):
Expand Down
2 changes: 1 addition & 1 deletion samples/asynctests/test_azure_iothub_receive_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_logger(level):
return uamqp_logger


log = get_logger(logging.DEBUG)
log = get_logger(logging.INFO)


def _generate_sas_token(uri, policy, key, expiry=None):
Expand Down
2 changes: 1 addition & 1 deletion samples/asynctests/test_azure_iothub_send_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_logger(level):
return uamqp_logger


log = get_logger(logging.DEBUG)
log = get_logger(logging.INFO)


def _generate_sas_token(uri, policy, key, expiry=None):
Expand Down
2 changes: 1 addition & 1 deletion samples/test_azure_iothub_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_logger(level):
return uamqp_logger


log = get_logger(logging.DEBUG)
log = get_logger(logging.INFO)


def _build_iothub_amqp_endpoint_from_target(target):
Expand Down
2 changes: 1 addition & 1 deletion samples/test_azure_iothub_receive2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_logger(level):
return uamqp_logger


log = get_logger(logging.DEBUG)
log = get_logger(logging.INFO)


def _generate_sas_token(uri, policy, key, expiry=None):
Expand Down
2 changes: 1 addition & 1 deletion samples/test_azure_iothub_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_logger(level):
return uamqp_logger


log = get_logger(logging.DEBUG)
log = get_logger(logging.INFO)


def _generate_sas_token(uri, policy, key, expiry=None):
Expand Down
11 changes: 10 additions & 1 deletion uamqp/async_ops/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ def __init__(
error_policy=None,
keep_alive_interval=None,
**kwargs):
self.loop = loop or get_running_loop()

if loop:
self.loop = loop
else:
try:
if not self.loop: # from sub class instance
self.loop = get_running_loop()
except AttributeError:
self.loop = get_running_loop()

Copy link
Member

Choose a reason for hiding this comment

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

I think this code could be simplified with:

self.loop = loop
if not self.loop:
    self.loop = get_running_loop()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid we can't simplify it this way.

For an instance of SendClientAsync which extends from AMQPClientAsync, it first initializes its own self.loop member in the SendClientAsync constructor and then it will call its fathers init function. If we write self.loop = loop in AMQPClientAsync constructor, the loop member instance of the SendClientAsync will be overwritten to None (The default loop parameter is None in AMQPClientAsync init) which leads to a bug.

Let me know if you want a more detailed explanation.

super(AMQPClientAsync, self).__init__(
remote_address,
auth=auth,
Expand Down