Skip to content

Commit

Permalink
fixup: handle error in client.py
Browse files Browse the repository at this point in the history
  • Loading branch information
stintel committed Nov 22, 2022
1 parent c9ea651 commit 91828dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tavern/_plugins/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _on_message(client, userdata, message):
except Full:
logger.exception("message queue full")

def message_received(self, timeout=1):
def message_received(self, unexpected=False, timeout=1):
"""Check that a message is in the message queue
Args:
Expand All @@ -215,7 +215,8 @@ def message_received(self, timeout=1):
try:
msg = self._message_queue.get(block=True, timeout=timeout)
except Empty:
logger.error("Message not received after %d seconds", timeout)
if not unexpected:
logger.error("Message not received after %d seconds", timeout)
return None
else:
return msg
Expand Down
3 changes: 2 additions & 1 deletion tavern/_plugins/mqtt/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _await_response(self):

topic = self.expected["topic"]
timeout = self.expected.get("timeout", 1)
unexpected = self.expected.get("unexpected")

test_strictness = self.test_block_config["strict"]
block_strictness = test_strictness.setting_for("json")
Expand All @@ -78,7 +79,7 @@ def addwarning(w, *args, **kwargs):
while time_spent < timeout:
t0 = time.time()

msg = self._client.message_received(timeout - time_spent)
msg = self._client.message_received(unexpected, timeout - time_spent)

if not msg:
# timed out
Expand Down

0 comments on commit 91828dd

Please sign in to comment.