2013-11-12 15:55:57 -08:00
|
|
|
import pytest
|
|
|
|
import capnp
|
|
|
|
import os
|
2013-11-12 19:38:34 -08:00
|
|
|
import socket
|
2013-11-12 15:55:57 -08:00
|
|
|
|
2013-12-09 17:13:43 -08:00
|
|
|
import test_capability_capnp
|
2013-11-12 15:55:57 -08:00
|
|
|
|
2013-12-09 17:13:43 -08:00
|
|
|
class Server(test_capability_capnp.TestInterface.Server):
|
2013-11-12 15:55:57 -08:00
|
|
|
def __init__(self, val=1):
|
|
|
|
self.val = val
|
|
|
|
|
2013-11-14 23:06:14 -08:00
|
|
|
def foo(self, i, j, **kwargs):
|
|
|
|
return str(i * 5 + self.val)
|
2013-11-12 15:55:57 -08:00
|
|
|
|
2013-12-09 17:13:43 -08:00
|
|
|
def test_simple_rpc():
|
2013-11-12 15:55:57 -08:00
|
|
|
def _restore(ref_id):
|
2013-12-09 17:13:43 -08:00
|
|
|
return Server(100)
|
2013-11-12 15:55:57 -08:00
|
|
|
|
2013-11-12 19:38:34 -08:00
|
|
|
read, write = socket.socketpair(socket.AF_UNIX)
|
|
|
|
|
2013-12-09 17:13:43 -08:00
|
|
|
restorer = capnp.Restorer(test_capability_capnp.TestSturdyRefObjectId, _restore)
|
2013-12-02 17:38:32 -08:00
|
|
|
server = capnp.RpcServer(write, restorer)
|
|
|
|
client = capnp.RpcClient(read)
|
2013-11-12 15:55:57 -08:00
|
|
|
|
2013-12-09 17:13:43 -08:00
|
|
|
ref = test_capability_capnp.TestSturdyRefObjectId.new_message()
|
2013-11-12 19:38:34 -08:00
|
|
|
cap = client.restore(ref)
|
2013-12-09 17:13:43 -08:00
|
|
|
cap = cap.cast_as(test_capability_capnp.TestInterface)
|
2013-11-12 15:55:57 -08:00
|
|
|
|
|
|
|
remote = cap.foo(i=5)
|
2013-12-02 17:38:32 -08:00
|
|
|
response = remote.wait()
|
2013-11-12 15:55:57 -08:00
|
|
|
|
|
|
|
assert response.x == '125'
|