Change server instantion to be inherited
This commit is contained in:
@@ -3,32 +3,28 @@ import capnp
|
||||
import os
|
||||
import socket
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
import test_capability_capnp
|
||||
|
||||
@pytest.fixture
|
||||
def capability():
|
||||
return capnp.load(os.path.join(this_dir, 'test_capability.capnp'))
|
||||
|
||||
class Server:
|
||||
class Server(test_capability_capnp.TestInterface.Server):
|
||||
def __init__(self, val=1):
|
||||
self.val = val
|
||||
|
||||
def foo(self, i, j, **kwargs):
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
def test_simple_rpc(capability):
|
||||
def test_simple_rpc():
|
||||
def _restore(ref_id):
|
||||
return capability.TestInterface.new_server(Server(100))
|
||||
return Server(100)
|
||||
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
restorer = capnp.Restorer(capability.TestSturdyRefObjectId, _restore)
|
||||
restorer = capnp.Restorer(test_capability_capnp.TestSturdyRefObjectId, _restore)
|
||||
server = capnp.RpcServer(write, restorer)
|
||||
client = capnp.RpcClient(read)
|
||||
|
||||
ref = capability.TestSturdyRefObjectId.new_message()
|
||||
ref = test_capability_capnp.TestSturdyRefObjectId.new_message()
|
||||
cap = client.restore(ref)
|
||||
cap = cap.cast_as(capability.TestInterface)
|
||||
cap = cap.cast_as(test_capability_capnp.TestInterface)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
response = remote.wait()
|
||||
|
||||
Reference in New Issue
Block a user