Various fixups to the RPC api.

* change how restorer works
* fix join_promises
* add incref's all around to make sure we aren't freeing objects early
* make it so we return PyPromises everywhere and make chains collapsible
This commit is contained in:
Jason Paryani
2013-12-10 22:57:21 -08:00
parent bba1918566
commit e92f7b56c6
10 changed files with 267 additions and 1360 deletions

View File

@@ -12,17 +12,60 @@ class Server(test_capability_capnp.TestInterface.Server):
def foo(self, i, j, **kwargs):
return str(i * 5 + self.val)
def test_simple_rpc():
def _restore(ref_id):
class TypelessRestorer:
def restore(self, ref_id):
return Server(100)
def restore_func(ref_id):
return Server(100)
class SimpleRestorer(test_capability_capnp.TestSturdyRefObjectId.Restorer):
def restore(self, ref_id):
assert ref_id.tag == 'testInterface'
return Server(100)
def test_simple_rpc():
read, write = socket.socketpair(socket.AF_UNIX)
restorer = capnp.Restorer(test_capability_capnp.TestSturdyRefObjectId, _restore)
server = capnp.RpcServer(write, restorer)
client = capnp.RpcClient(read)
restorer = SimpleRestorer()
server = capnp.TwoPartyServer(write, restorer)
client = capnp.TwoPartyClient(read)
ref = test_capability_capnp.TestSturdyRefObjectId.new_message()
ref = test_capability_capnp.TestSturdyRefObjectId.new_message(tag='testInterface')
cap = client.restore(ref)
cap = cap.cast_as(test_capability_capnp.TestInterface)
remote = cap.foo(i=5)
response = remote.wait()
assert response.x == '125'
def test_simple_rpc_typeless_restorer():
read, write = socket.socketpair(socket.AF_UNIX)
restorer = TypelessRestorer()
server = capnp.TwoPartyServer(write, restorer)
client = capnp.TwoPartyClient(read)
ref = test_capability_capnp.TestSturdyRefObjectId.new_message(tag='testInterface')
cap = client.restore(ref)
cap = cap.cast_as(test_capability_capnp.TestInterface)
remote = cap.foo(i=5)
response = remote.wait()
assert response.x == '125'
def test_simple_rpc_restore_func():
read, write = socket.socketpair(socket.AF_UNIX)
server = capnp.TwoPartyServer(write, restore_func)
client = capnp.TwoPartyClient(read)
ref = test_capability_capnp.TestSturdyRefObjectId.new_message(tag='testInterface')
cap = client.restore(ref)
cap = cap.cast_as(test_capability_capnp.TestInterface)