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.
|
does not initialize the frame helper or send the hello message.
|
||||||
"""
|
"""
|
||||||
if self.connection_state is not ConnectionState.INITIALIZED:
|
if self.connection_state is not ConnectionState.INITIALIZED:
|
||||||
raise ValueError(
|
raise RuntimeError(
|
||||||
"Connection can only be used once, connection is not in init state"
|
"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)
|
mock_data_received(protocol, message_with_bad_protobuf_data)
|
||||||
assert "Invalid protobuf message: type=TextSensorStateResponse" in caplog.text
|
assert "Invalid protobuf message: type=TextSensorStateResponse" in caplog.text
|
||||||
assert connection.is_connected is False
|
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