2016-06-17 13:50:42 -07:00
|
|
|
import test_response_capnp
|
|
|
|
|
2019-12-11 22:44:44 -08:00
|
|
|
|
2016-06-17 13:50:42 -07:00
|
|
|
class FooServer(test_response_capnp.Foo.Server):
|
|
|
|
def __init__(self, val=1):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def foo(self, **kwargs):
|
|
|
|
return 1
|
|
|
|
|
2019-12-11 22:44:44 -08:00
|
|
|
|
2016-06-17 13:50:42 -07:00
|
|
|
class BazServer(test_response_capnp.Baz.Server):
|
|
|
|
def __init__(self, val=1):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def grault(self, **kwargs):
|
|
|
|
return {"foo": FooServer()}
|
|
|
|
|
2019-12-11 22:44:44 -08:00
|
|
|
|
2016-06-17 13:50:42 -07:00
|
|
|
def test_response_reference():
|
|
|
|
baz = test_response_capnp.Baz._new_client(BazServer())
|
|
|
|
|
|
|
|
bar = baz.grault().wait().bar
|
|
|
|
|
|
|
|
foo = bar.foo
|
|
|
|
# This used to cause an exception about invalid pointers because the response got garbage collected
|
2016-06-17 13:53:48 -07:00
|
|
|
assert foo.foo().wait().val == 1
|
2016-06-17 13:50:42 -07:00
|
|
|
|
2019-12-11 22:44:44 -08:00
|
|
|
|
2016-06-17 13:50:42 -07:00
|
|
|
def test_response_reference2():
|
|
|
|
baz = test_response_capnp.Baz._new_client(BazServer())
|
|
|
|
|
|
|
|
bar = baz.grault().wait().bar
|
|
|
|
|
|
|
|
# This always worked since it saved the intermediate response object
|
|
|
|
response = baz.grault().wait()
|
|
|
|
bar = response.bar
|
|
|
|
foo = bar.foo
|
2016-06-17 13:53:48 -07:00
|
|
|
assert foo.foo().wait().val == 1
|