13
test/test_response.capnp
Normal file
13
test/test_response.capnp
Normal file
@@ -0,0 +1,13 @@
|
||||
@0x84249be5c3bff005;
|
||||
|
||||
interface Foo {
|
||||
foo @0 () -> (val :UInt32);
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
foo @0 :Foo;
|
||||
}
|
||||
|
||||
interface Baz {
|
||||
grault @0 () -> (bar: Bar);
|
||||
}
|
||||
40
test/test_response.py
Normal file
40
test/test_response.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import time
|
||||
|
||||
import test_response_capnp
|
||||
|
||||
class FooServer(test_response_capnp.Foo.Server):
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def foo(self, **kwargs):
|
||||
return 1
|
||||
|
||||
class BazServer(test_response_capnp.Baz.Server):
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def grault(self, **kwargs):
|
||||
return {"foo": FooServer()}
|
||||
|
||||
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
|
||||
foo.foo().wait()
|
||||
|
||||
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
|
||||
foo.foo().wait()
|
||||
Reference in New Issue
Block a user