mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
feat(tunnel): 引入 aether-hub 帧路由器,支持多 worker 共享 tunnel 连接
新增 Rust 实现的 aether-hub 服务,作为 Docker 容器内部 WebSocket 帧路由器, 解决多 Gunicorn worker 进程间 tunnel 连接隔离问题。 主要改动: - 新增 aether-hub Rust 项目,实现 proxy/worker 双向帧路由与 stream_id 重映射 - 新增 HubConnectionManager/HubTunnelTransport,worker 通过 Hub 转发 tunnel 帧 - 新增 create_tunnel_transport 工厂函数,按运行环境自动选择 Hub 或直连模式 - 新增 NODE_STATUS 广播机制,Hub 实时通知所有 worker 节点连接状态变化 - CI/CD 新增 build-hub job,Dockerfile 集成 Hub 二进制,deploy.sh 适配 Hub 构建 - 默认 GUNICORN_WORKERS 从 4 降为 2
This commit is contained in:
34
tests/unit/test_tunnel_hub_factory.py
Normal file
34
tests/unit/test_tunnel_hub_factory.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
|
||||
from src.services.proxy_node.hub_config import reset_hub_config_cache
|
||||
from src.services.proxy_node.hub_transport import HubTunnelTransport
|
||||
from src.services.proxy_node.tunnel_protocol import Frame, MsgType
|
||||
from src.services.proxy_node.tunnel_transport import TunnelTransport, create_tunnel_transport
|
||||
|
||||
|
||||
def test_create_tunnel_transport_uses_legacy_transport_when_hub_disabled(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("DOCKER_CONTAINER", "false")
|
||||
monkeypatch.setattr("src.services.proxy_node.hub_config.os.path.exists", lambda _: False)
|
||||
reset_hub_config_cache()
|
||||
|
||||
transport = create_tunnel_transport("node-1", timeout=12.0)
|
||||
assert isinstance(transport, TunnelTransport)
|
||||
|
||||
|
||||
def test_create_tunnel_transport_uses_hub_transport_when_hub_enabled(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("DOCKER_CONTAINER", "true")
|
||||
monkeypatch.setattr("src.services.proxy_node.hub_config.os.path.exists", lambda _: False)
|
||||
reset_hub_config_cache()
|
||||
|
||||
transport = create_tunnel_transport("node-1", timeout=12.0)
|
||||
assert isinstance(transport, HubTunnelTransport)
|
||||
|
||||
|
||||
def test_tunnel_protocol_supports_node_status_msg_type() -> None:
|
||||
raw = Frame(0, MsgType.NODE_STATUS, 0, b'{"node_id":"n1","connected":true}').encode()
|
||||
decoded = Frame.decode(raw)
|
||||
assert decoded.msg_type == MsgType.NODE_STATUS
|
||||
Reference in New Issue
Block a user