Fix remaining type issues
This commit is contained in:
parent
f1aad14099
commit
e0efb2853b
@ -4,6 +4,7 @@ import asyncio
|
||||
|
||||
import pytest
|
||||
import veilid
|
||||
from veilid.types import OperationId
|
||||
|
||||
from .conftest import server_info
|
||||
|
||||
@ -20,7 +21,8 @@ async def test_routing_contexts(api_connection):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_routing_context_app_message_loopback():
|
||||
app_message_queue = asyncio.Queue()
|
||||
# Seriously, mypy?
|
||||
app_message_queue: asyncio.Queue = asyncio.Queue()
|
||||
|
||||
async def app_message_queue_update_callback(update: veilid.VeilidUpdate):
|
||||
if update.kind == veilid.VeilidUpdateKind.APP_MESSAGE:
|
||||
@ -51,13 +53,14 @@ async def test_routing_context_app_message_loopback():
|
||||
update: veilid.VeilidUpdate = await asyncio.wait_for(
|
||||
app_message_queue.get(), timeout=10
|
||||
)
|
||||
appmsg: veilid.VeilidAppMessage = update.detail
|
||||
assert appmsg.message == message
|
||||
|
||||
assert isinstance(update.detail, veilid.VeilidAppMessage)
|
||||
assert update.detail.message == message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_routing_context_app_call_loopback():
|
||||
app_call_queue = asyncio.Queue()
|
||||
app_call_queue: asyncio.Queue = asyncio.Queue()
|
||||
|
||||
async def app_call_queue_update_callback(update: veilid.VeilidUpdate):
|
||||
if update.kind == veilid.VeilidUpdateKind.APP_CALL:
|
||||
@ -88,12 +91,19 @@ async def test_routing_context_app_call_loopback():
|
||||
update: veilid.VeilidUpdate = await asyncio.wait_for(
|
||||
app_call_queue.get(), timeout=10
|
||||
)
|
||||
appcall: veilid.VeilidAppCall = update.detail
|
||||
appcall = update.detail
|
||||
|
||||
assert isinstance(appcall, veilid.VeilidAppCall)
|
||||
assert appcall.message == request
|
||||
|
||||
# now we reply to the request
|
||||
reply = b"qwer5678"
|
||||
await api.app_call_reply(appcall.call_id, reply)
|
||||
# TK: OperationId use to be a subclass of `int`. When I wrapped `appcall.call_id` in int(),
|
||||
# this failed JSON schema validation, which defines `call_id` as a string. Maybe that was a
|
||||
# typo, and OperationId is really *supposed* to be a str? Alternatively, perhaps the
|
||||
# signature of `app_call_reply` is wrong and it's supposed to take a type other than
|
||||
# OperationId?
|
||||
await api.app_call_reply(OperationId(appcall.call_id), reply)
|
||||
|
||||
# now we should get the reply from the call
|
||||
result = await app_call_task
|
||||
|
@ -49,8 +49,8 @@ _VALIDATOR_RECV_MESSAGE = _get_schema_validator(
|
||||
|
||||
|
||||
class _JsonVeilidAPI(VeilidAPI):
|
||||
reader: asyncio.StreamReader
|
||||
writer: asyncio.StreamWriter
|
||||
reader: Optional[asyncio.StreamReader]
|
||||
writer: Optional[asyncio.StreamWriter]
|
||||
update_callback: Callable[[VeilidUpdate], Awaitable]
|
||||
handle_recv_messages_task: Optional[asyncio.Task]
|
||||
validate_schemas: bool
|
||||
@ -85,6 +85,7 @@ class _JsonVeilidAPI(VeilidAPI):
|
||||
await self.lock.acquire()
|
||||
try:
|
||||
self.reader = None
|
||||
assert self.writer is not None
|
||||
self.writer.close()
|
||||
await self.writer.wait_closed()
|
||||
self.writer = None
|
||||
@ -138,6 +139,7 @@ class _JsonVeilidAPI(VeilidAPI):
|
||||
async def handle_recv_messages(self):
|
||||
# Read lines until we're done
|
||||
try:
|
||||
assert self.reader is not None
|
||||
while True:
|
||||
linebytes = await self.reader.readline()
|
||||
if not linebytes.endswith(b"\n"):
|
||||
@ -225,6 +227,7 @@ class _JsonVeilidAPI(VeilidAPI):
|
||||
|
||||
# Send to socket
|
||||
try:
|
||||
assert writer is not None
|
||||
writer.write(reqbytes)
|
||||
await writer.drain()
|
||||
except Exception:
|
||||
|
@ -82,7 +82,7 @@ class ByteCount(int):
|
||||
pass
|
||||
|
||||
|
||||
class OperationId(int):
|
||||
class OperationId(str):
|
||||
pass
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user