Allow cancellation of all capability contexts

This commit is contained in:
Lasse Blaauwbroek
2023-10-28 07:03:42 +02:00
committed by Jacob Alexander
parent 49bda5ccae
commit 0ec4d0b778
4 changed files with 41 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
import pytest
import asyncio
import capnp
import test_capability_capnp as capability
@@ -389,3 +390,22 @@ async def test_generic():
obj = capnp._MallocMessageBuilder().get_root_as_any()
obj.set_as_text("anypointer_")
assert (await client.foo(obj)).b == "anypointer_test"
class CancelServer(capability.TestInterface.Server):
def __init__(self, val=1):
self.val = val
async def foo(self, i, j, **kwargs):
with pytest.raises(asyncio.CancelledError):
await asyncio.sleep(10)
async def test_cancel2():
client = capability.TestInterface._new_client(CancelServer())
task = asyncio.ensure_future(client.foo(1, True))
await asyncio.sleep(0) # Make sure that the task runs
task.cancel()
with pytest.raises(asyncio.CancelledError):
await task