Parcourir la source

test(apilot): discriminate cross-call half-packet regression; expose make_msg_object

wuzilong il y a 2 mois
Parent
commit
74ad22d135
2 fichiers modifiés avec 11 ajouts et 7 suppressions
  1. 8 4
      apilot/stubs/networkctl.py
  2. 3 3
      tests/test_wire.py

+ 8 - 4
apilot/stubs/networkctl.py

@@ -79,13 +79,17 @@ LuaNetworkController = {Inst = function() return networkCtl end}
         self._installed.add(id(lua))
 
 
+def make_msg_object(lua: Any, frame: Frame) -> Any:
+    """名义接口: 等价 AP_mkmsg 闭包,按帧构造 Lua msg 对象(需先 install_to_lua)。"""
+    mkmsg = lua.globals()["AP_mkmsg"]
+    body = frame.body.decode("latin-1")
+    return mkmsg(frame.recog, frame.msg_id, frame.p1, frame.p2, frame.p3, body)
+
+
 def dispatch_frame(lua: Any, ctl: NetworkCtlStub, f: Frame) -> None:
     cb = ctl.handlers.get(f.msg_id)
     if cb is None:
         return
     if id(lua) not in ctl._installed:
         ctl.install_to_lua(lua)
-    mkmsg = lua.globals()["AP_mkmsg"]
-    body = f.body.decode("latin-1")
-    msg = mkmsg(f.recog, f.msg_id, f.p1, f.p2, f.p3, body)
-    cb(msg)
+    cb(make_msg_object(lua, f))

+ 3 - 3
tests/test_wire.py

@@ -55,7 +55,7 @@ def test_recv_buffered_across_calls():
                 pass
             conn.setblocking(True)
             conn.sendall(wire_bytes[:mid])  # 第一半
-            time.sleep(0.2)
+            time.sleep(0.45)
             conn.sendall(wire_bytes[mid:])  # 第二半
             time.sleep(0.2)
         finally:
@@ -65,8 +65,8 @@ def test_recv_buffered_across_calls():
     threading.Thread(target=gateway, daemon=True).start()
 
     w = Wire("127.0.0.1", port, timeout=2.0)
-    f1 = w.recv(0.3)            # 只能拿到第一半
-    f2 = w.recv(0.3)            # 第二半在此次补齐
+    f1 = w.recv(0.15)           # 首次窗口小于网关间隔,只可能拿到第一半
+    f2 = w.recv(0.4)            # 第二半在此次补齐
     w.close()
     all_frames = f1 + f2
     assert len([f for f in all_frames if f.msg_id == 529]) == 1, f"got {all_frames}"