fix: use fresh beaver message id after reconnect
This commit is contained in:
@ -88,13 +88,13 @@ class BeaverTerminalClient:
|
|||||||
self.session_id = session_id if isinstance(session_id, str) else None
|
self.session_id = session_id if isinstance(session_id, str) else None
|
||||||
|
|
||||||
async def send_text(self, text: str) -> str:
|
async def send_text(self, text: str) -> str:
|
||||||
message_id = self._message_ids.next_id()
|
|
||||||
message_frame = build_message_frame(message_id=message_id, text=text)
|
|
||||||
|
|
||||||
for attempt in range(2):
|
for attempt in range(2):
|
||||||
if not self._websocket_is_open():
|
if not self._websocket_is_open():
|
||||||
await self.connect()
|
await self.connect()
|
||||||
|
|
||||||
|
message_id = self._message_ids.next_id()
|
||||||
|
message_frame = build_message_frame(message_id=message_id, text=text)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self._send_json(message_frame)
|
await self._send_json(message_frame)
|
||||||
return await self._wait_for_reply(message_id)
|
return await self._wait_for_reply(message_id)
|
||||||
|
|||||||
@ -340,6 +340,7 @@ async def test_client_reconnects_with_same_peer_id_when_socket_closes_before_sen
|
|||||||
unused_tcp_port: int,
|
unused_tcp_port: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
connect_peer_ids: list[str] = []
|
connect_peer_ids: list[str] = []
|
||||||
|
message_ids: list[str] = []
|
||||||
connection_count = 0
|
connection_count = 0
|
||||||
|
|
||||||
async def websocket_handler(request: web.Request) -> web.WebSocketResponse:
|
async def websocket_handler(request: web.Request) -> web.WebSocketResponse:
|
||||||
@ -360,9 +361,11 @@ async def test_client_reconnects_with_same_peer_id_when_socket_closes_before_sen
|
|||||||
"session_id": "terminal-dev:local:device-001",
|
"session_id": "terminal-dev:local:device-001",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
elif frame["type"] == "message":
|
||||||
|
message_ids.append(frame["message_id"])
|
||||||
if current_connection == 1:
|
if current_connection == 1:
|
||||||
await ws.close()
|
await ws.close()
|
||||||
elif frame["type"] == "message":
|
continue
|
||||||
await ws.send_json(
|
await ws.send_json(
|
||||||
{
|
{
|
||||||
"type": "ack",
|
"type": "ack",
|
||||||
@ -407,3 +410,4 @@ async def test_client_reconnects_with_same_peer_id_when_socket_closes_before_sen
|
|||||||
|
|
||||||
assert reply == "reply after reconnect"
|
assert reply == "reply after reconnect"
|
||||||
assert connect_peer_ids == ["device-001", "device-001"]
|
assert connect_peer_ids == ["device-001", "device-001"]
|
||||||
|
assert message_ids == ["device-001-000001", "device-001-000002"]
|
||||||
|
|||||||
Reference in New Issue
Block a user