issues, chat FPS; optimisations
This commit is contained in:
@@ -372,6 +372,70 @@ def test_relay_rpc_round_trips_http_request_to_peer():
|
||||
assert json.loads(response["body"]) == {"ok": True, "path": "/v1/chat/completions"}
|
||||
|
||||
|
||||
def test_relay_rpc_reuses_connection_for_sequential_requests(monkeypatch):
|
||||
"""One route session should not repeat the WebSocket handshake per token."""
|
||||
import websockets.sync.client as wsc # type: ignore[import]
|
||||
from meshnet_node.relay_bridge import decode_binary_frame, encode_binary_frame
|
||||
from meshnet_node.torch_server import _RelayHopClient
|
||||
from meshnet_relay.server import RelayServer
|
||||
|
||||
relay = RelayServer(host="127.0.0.1", port=0)
|
||||
port = relay.start()
|
||||
ready = threading.Event()
|
||||
|
||||
def run_peer():
|
||||
with wsc.connect(f"ws://127.0.0.1:{port}/ws") as ws:
|
||||
ws.send(json.dumps({
|
||||
"topic": "peer-register",
|
||||
"version": 1,
|
||||
"from_peer": "persistent_peer",
|
||||
"msg_id": "persistent-reg-001",
|
||||
"payload": {"peer_id": "persistent_peer", "addr": ""},
|
||||
}))
|
||||
ws.recv()
|
||||
ready.set()
|
||||
for _ in range(2):
|
||||
raw = ws.recv(timeout=3)
|
||||
header, body = decode_binary_frame(raw)
|
||||
ws.send(encode_binary_frame({
|
||||
"request_id": header["request_id"],
|
||||
"status": 200,
|
||||
"headers": {"Content-Type": "application/octet-stream"},
|
||||
}, body))
|
||||
|
||||
peer_thread = threading.Thread(target=run_peer, daemon=True)
|
||||
peer_thread.start()
|
||||
assert ready.wait(timeout=5)
|
||||
|
||||
real_connect = wsc.connect
|
||||
connection_attempts = 0
|
||||
|
||||
def tracked_connect(*args, **kwargs):
|
||||
nonlocal connection_attempts
|
||||
connection_attempts += 1
|
||||
return real_connect(*args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(wsc, "connect", tracked_connect)
|
||||
client = _RelayHopClient(f"ws://127.0.0.1:{port}/rpc/persistent_peer", timeout=5)
|
||||
try:
|
||||
responses = [
|
||||
client.request(
|
||||
"/forward",
|
||||
f"token-{index}".encode(),
|
||||
{"X-Meshnet-Session": "route-session"},
|
||||
)
|
||||
for index in range(2)
|
||||
]
|
||||
finally:
|
||||
client.close()
|
||||
relay.stop()
|
||||
peer_thread.join(timeout=3)
|
||||
|
||||
assert [status for status, _, _ in responses] == [200, 200]
|
||||
assert [body for _, _, body in responses] == [b"token-0", b"token-1"]
|
||||
assert connection_attempts == 1
|
||||
|
||||
|
||||
def test_binary_relay_frame_codecs_interoperate():
|
||||
"""Node and relay ship the same binary frame format as separate copies."""
|
||||
import os
|
||||
|
||||
Reference in New Issue
Block a user