mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-22 12:05:12 +01:00
Add test for attempting to reuse an APIConnection object raises (#703)
This commit is contained in:
parent
554190228e
commit
b67e19bd94
@ -512,7 +512,7 @@ class APIConnection:
|
||||
does not initialize the frame helper or send the hello message.
|
||||
"""
|
||||
if self.connection_state is not ConnectionState.INITIALIZED:
|
||||
raise ValueError(
|
||||
raise RuntimeError(
|
||||
"Connection can only be used once, connection is not in init state"
|
||||
)
|
||||
|
||||
|
@ -769,3 +769,18 @@ async def test_bad_protobuf_message_drops_connection(
|
||||
mock_data_received(protocol, message_with_bad_protobuf_data)
|
||||
assert "Invalid protobuf message: type=TextSensorStateResponse" in caplog.text
|
||||
assert connection.is_connected is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_connection_cannot_be_reused(
|
||||
plaintext_connect_task_with_login: tuple[
|
||||
APIConnection, asyncio.Transport, APIPlaintextFrameHelper, asyncio.Task
|
||||
],
|
||||
) -> None:
|
||||
"""Test that we raise when trying to connect when already connected."""
|
||||
conn, transport, protocol, connect_task = plaintext_connect_task_with_login
|
||||
send_plaintext_hello(protocol)
|
||||
send_plaintext_connect_response(protocol, False)
|
||||
await connect_task
|
||||
with pytest.raises(RuntimeError):
|
||||
await conn.start_connection()
|
||||
|
Loading…
Reference in New Issue
Block a user