fix: await Dynamips.create_nio (it is async, unlike sync base)

Dynamips.create_nio is async def while BaseManager.create_nio is a sync
def.  The previous fix only added the extra 'node' argument but did not
await the resulting coroutine, causing 'was never awaited' warnings and
passing a coroutine object instead of an NIO instance to the binding
dispatch.  Add 'await' on the Dynamips branch.  Test updated to verify
both the async nature and the parameter count.
This commit is contained in:
YueGuobin committed 2026-08-11 01:00:01 +08:00
1 parent 09a9555d02
commit 4e30b6905a
2 files changed
+19 -15

No files matched your search

+15 -8
View File
@@ -258,27 +258,34 @@ class TestBatchNIOEdgeCases:
node.add_nio.assert_called_once_with(nio, 0)
@pytest.mark.asyncio
async def test_dynamips_create_nio_passes_node_arg(self):
async def test_dynamips_create_nio_is_async_and_needs_await(self):
"""
Dynamips.create_nio(self, node, nio_settings) exposes 2 bound-method
params vs. the standard 1. The batch handler detects this via the
parameter count on the bound method and passes the extra 'node'
argument.
Dynamips.create_nio is async (returns a coroutine) unlike the sync
base version. The batch handler must await it.
"""
import inspect
import asyncio as _asyncio
class _FakeDynamips:
async def create_nio(self, node, nio_settings):
pass
return {"type": "nio_udp", "node": node}
class _FakeBase:
async def create_nio(self, nio_settings):
pass
def create_nio(self, nio_settings):
return {"type": "nio_udp"}
dyn = _FakeDynamips()
base = _FakeBase()
assert len(inspect.signature(dyn.create_nio).parameters) == 2 # Dynamips
assert len(inspect.signature(base.create_nio).parameters) == 1 # standard
assert inspect.iscoroutinefunction(dyn.create_nio)
assert not inspect.iscoroutinefunction(base.create_nio)
# Verify the batch logic: 2 params → await, 1 param → no await
d_result = await dyn.create_nio("r1", {"type": "nio_udp"})
b_result = base.create_nio({"type": "nio_udp"})
assert d_result["node"] == "r1"
assert b_result["type"] == "nio_udp"
@pytest.mark.asyncio
async def test_qemu_dispatch_to_adapter_add_nio_binding(self):