modify: 混合模式——按插件 load_mode 共存(inline/external 由 Docker/K8s 编排)
This commit is contained in:
+25
-4
@@ -1,10 +1,11 @@
|
||||
"""
|
||||
RouteRegistry 单元测试(loopback Zenoh 会话 + httpx ASGI 功能断言)
|
||||
|
||||
验证 process 模式核心链路:
|
||||
验证 external 插件路由动态注册核心链路(含混合模式防双注册):
|
||||
RoutePublisher.put 描述符 → 网关 RouteRegistry 动态挂载 FastAPI 路由(命中返回 503,worker 桩无实例)
|
||||
RoutePublisher.delete → 动态摘除路由(404)
|
||||
__meta__ 中的 mqtt_topics → 推送给 MQTT Bridge(update_custom_topics)
|
||||
__meta__ 中的 mqtt_topics → 推送给 MQTT Bridge(update_dynamic_topics)
|
||||
set_inline_types → 忽略 inline 插件的描述符(防双注册)
|
||||
|
||||
注:FastAPI 0.139 的 include_router 将路由包装为 _IncludedRouter(惰性挂载),
|
||||
不能靠遍历 app.router.routes 的 path 判断,故用 ASGI 请求状态码做功能断言。
|
||||
@@ -37,12 +38,12 @@ class FakeWorkerManager:
|
||||
|
||||
|
||||
class FakeBridge:
|
||||
"""记录 update_custom_topics 的调用结果。"""
|
||||
"""记录 update_dynamic_topics 的调用结果。"""
|
||||
|
||||
def __init__(self):
|
||||
self.topics = None
|
||||
|
||||
async def update_custom_topics(self, topics):
|
||||
async def update_dynamic_topics(self, topics):
|
||||
self.topics = list(topics)
|
||||
|
||||
|
||||
@@ -145,6 +146,26 @@ async def main():
|
||||
check("delete 后 HTTP 路由动态摘除(404)", ok)
|
||||
ok = await wait_until(lambda: bridge.topics == [])
|
||||
check("元信息摘除后 Bridge 主题清空", ok, f"bridge.topics={bridge.topics}")
|
||||
|
||||
# 5. 混合模式:inline 类型的描述符被忽略(防与盘扫注册重复挂载)
|
||||
registry.set_inline_types({"example"})
|
||||
publisher.publish_routes([HTTP_DESCRIPTOR])
|
||||
await asyncio.sleep(3.5) # 覆盖防抖窗口
|
||||
resp = await client.get("/api/v1/calc/add?a=1&b=2")
|
||||
check("inline 类型描述符被忽略(防双注册,404)", resp.status_code == 404,
|
||||
f"status={resp.status_code}")
|
||||
|
||||
# 清除 inline 集合后恢复动态挂载
|
||||
registry.set_inline_types(set())
|
||||
publisher.publish_routes([HTTP_DESCRIPTOR])
|
||||
|
||||
async def remounted():
|
||||
resp = await client.get("/api/v1/calc/add?a=1&b=2")
|
||||
return resp.status_code == 503
|
||||
|
||||
ok = await wait_until(remounted)
|
||||
check("清除 inline 集合后恢复动态挂载", ok)
|
||||
publisher.unpublish()
|
||||
finally:
|
||||
registry.stop()
|
||||
gw_session.close()
|
||||
|
||||
Reference in New Issue
Block a user