Force server methods to be async and client calls to use await
This commit is contained in:
@@ -5,7 +5,7 @@ class FooServer(test_response_capnp.Foo.Server):
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def foo(self, **kwargs):
|
||||
async def foo(self, **kwargs):
|
||||
return 1
|
||||
|
||||
|
||||
@@ -13,27 +13,27 @@ class BazServer(test_response_capnp.Baz.Server):
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def grault(self, **kwargs):
|
||||
async def grault(self, **kwargs):
|
||||
return {"foo": FooServer()}
|
||||
|
||||
|
||||
async def test_response_reference():
|
||||
baz = test_response_capnp.Baz._new_client(BazServer())
|
||||
|
||||
bar = baz.grault().wait().bar
|
||||
bar = (await baz.grault()).bar
|
||||
|
||||
foo = bar.foo
|
||||
# This used to cause an exception about invalid pointers because the response got garbage collected
|
||||
assert foo.foo().wait().val == 1
|
||||
assert (await foo.foo()).val == 1
|
||||
|
||||
|
||||
async def test_response_reference2():
|
||||
baz = test_response_capnp.Baz._new_client(BazServer())
|
||||
|
||||
bar = baz.grault().wait().bar
|
||||
bar = (await baz.grault()).bar
|
||||
|
||||
# This always worked since it saved the intermediate response object
|
||||
response = baz.grault().wait()
|
||||
response = await baz.grault()
|
||||
bar = response.bar
|
||||
foo = bar.foo
|
||||
assert foo.foo().wait().val == 1
|
||||
assert (await foo.foo()).val == 1
|
||||
|
||||
Reference in New Issue
Block a user