Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
386 changes: 195 additions & 191 deletions azure-iot-device/azure/iot/device/common/mqtt_transport.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,15 @@ def on_complete(cancelled=False):
logger.debug("{}({}): subscribing to {}".format(self.name, op.name, op.topic))

@pipeline_thread.invoke_on_pipeline_thread_nowait
def on_complete(cancelled=False):
def on_complete(cancelled=False, error=None):
if cancelled:
op.complete(
error=pipeline_exceptions.OperationCancelled(
"Operation cancelled before SUBACK received"
)
)
elif error is not None:
op.complete(error=error)
else:
logger.debug(
"{}({}): SUBACK received. completing op.".format(self.name, op.name)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [
dependencies = [
"deprecation>=2.1.0,<3.0.0",
"janus",
"paho-mqtt>=2.0.0,<3.0.0",
"paho-mqtt>=2.1.0,<3.0.0",
"PySocks",
"requests>=2.32.3,<3.0.0",
"requests-unixsocket>=0.4.1",
Expand Down
25 changes: 19 additions & 6 deletions tests/unit/common/pipeline/test_pipeline_stages_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def test_complete(self, mocker, stage, op):
assert op.error is None

@pytest.mark.it(
"Completes the operation with an OperationCancelled error upon cancellation of the MQTT unsubscribe by the MQTTTransport"
"Completes the operation with an OperationCancelled error upon cancellation of the MQTT publish by the MQTTTransport"
)
def test_complete_with_cancel(self, mocker, stage, op):
# Begin publish
Expand Down Expand Up @@ -639,7 +639,7 @@ def op(self, mocker):
)

@pytest.mark.it("Performs an MQTT subscribe via the MQTTTransport")
def test_mqtt_publish(self, mocker, stage, op):
def test_mqtt_subscribe(self, mocker, stage, op):
stage.run_op(op)
assert stage.transport.subscribe.call_count == 1
assert stage.transport.subscribe.call_args == mocker.call(
Expand All @@ -662,10 +662,23 @@ def test_complete(self, mocker, stage, op):
assert op.error is None

@pytest.mark.it(
"Completes the operation with an OperationCancelled error upon cancellation of the MQTT unsubscribe by the MQTTTransport"
"Completes the operation with an error received from the MQTT subscribe callback"
)
def test_complete_with_error(self, stage, op, arbitrary_exception):
stage.run_op(op)

assert not op.completed

stage.transport.subscribe.call_args[1]["callback"](error=arbitrary_exception)

assert op.completed
assert op.error is arbitrary_exception

@pytest.mark.it(
"Completes the operation with an OperationCancelled error upon cancellation of the MQTT subscribe by the MQTTTransport"
)
def test_complete_with_cancel(self, mocker, stage, op):
# Begin unsubscribe
# Begin subscribe
stage.run_op(op)

assert not op.completed
Expand Down Expand Up @@ -699,7 +712,7 @@ def op(self, mocker):
)

@pytest.mark.it("Performs an MQTT unsubscribe via the MQTTTransport")
def test_mqtt_publish(self, mocker, stage, op):
def test_mqtt_unsubscribe(self, mocker, stage, op):
stage.run_op(op)
assert stage.transport.unsubscribe.call_count == 1
assert stage.transport.unsubscribe.call_args == mocker.call(
Expand Down Expand Up @@ -739,7 +752,7 @@ def test_complete_with_cancel(self, mocker, stage, op):
@pytest.mark.it(
"Completes the operation using the exception that was raised, if an exception was raised from the MQTTTransport"
)
def test_publish_error(self, stage, op, arbitrary_exception):
def test_unsubscribe_error(self, stage, op, arbitrary_exception):
stage.transport.unsubscribe.side_effect = arbitrary_exception

stage.run_op(op)
Expand Down
Loading