Skip to content
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
4 changes: 3 additions & 1 deletion amqtt/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ async def drain(self) -> None:
if not self.is_closed:
await self._writer.drain()

def get_peer_info(self) -> tuple[str, int]:
def get_peer_info(self) -> tuple[str, int] | None:
extra_info = self._writer.get_extra_info("peername")
if not extra_info or len(extra_info) < 2:
return None
return extra_info[0], extra_info[1]

def get_ssl_info(self) -> ssl.SSLObject | None:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,14 @@ async def test_broker_with_absent_auth_plugin_filter():
await mqtt_client.connect()

await broker.shutdown()


@pytest.mark.asyncio
async def test_client_without_peer_info(broker, mock_plugin_manager):
client = MQTTClient(config={'auto_reconnect':False})

# if the broker's stream writer for this client does not have peer info, the client should fail to connect
with patch.object(asyncio.streams.StreamWriter, 'get_extra_info', return_value=None) as mock_extra_info:
with pytest.raises(ConnectError):
await client.connect("mqtt://127.0.0.1/")
await asyncio.sleep(0.01)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some tests fail with timeout. I'm wondering if the rather short sleep could be one reason?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

appreciate the suggestion!

didn't get a chance to debug yesterday, should have a fix later today

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@HerrMuellerluedenscheid can you review when you get a chance?

Loading