Removing deprecated Restorer and ezRestore references
- Not recommended to be used in new designs - Just pollutes warning messages during compilation (hiding ones that should be fixed) - Updated test code to use bootstrap - Sped up some of the test code that was just sleeping while waiting for the server (now polling for the socket)
This commit is contained in:
@@ -10,7 +10,22 @@ examples_dir = os.path.join(os.path.dirname(__file__), '..', 'examples')
|
||||
|
||||
def run_subprocesses(address, server, client):
|
||||
server = subprocess.Popen([os.path.join(examples_dir, server), address])
|
||||
time.sleep(1) # Give the server some small amount of time to start listening
|
||||
retries = 30
|
||||
addr, port = address.split(':')
|
||||
while True:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
result = sock.connect_ex((addr, int(port)))
|
||||
if result == 0:
|
||||
break
|
||||
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
result = sock.connect_ex((addr, int(port)))
|
||||
if result == 0:
|
||||
break
|
||||
# Give the server some small amount of time to start listening
|
||||
time.sleep(0.1)
|
||||
retries -= 1
|
||||
if retries == 0:
|
||||
assert False, "Timed out waiting for server to start"
|
||||
client = subprocess.Popen([os.path.join(examples_dir, client), address])
|
||||
|
||||
ret = client.wait()
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
'''
|
||||
rpc test
|
||||
'''
|
||||
|
||||
import pytest
|
||||
import capnp
|
||||
import socket
|
||||
@@ -7,103 +11,28 @@ import test_capability_capnp
|
||||
|
||||
class Server(test_capability_capnp.TestInterface.Server):
|
||||
|
||||
def __init__(self, val=1):
|
||||
def __init__(self, val=100):
|
||||
self.val = val
|
||||
|
||||
def foo(self, i, j, **kwargs):
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
|
||||
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 = SimpleRestorer()
|
||||
_ = 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_with_options():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
restorer = SimpleRestorer()
|
||||
_ = capnp.TwoPartyServer(write, restorer)
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=Server())
|
||||
# This traversal limit is too low to receive the response in, so we expect
|
||||
# an exception during the call.
|
||||
client = capnp.TwoPartyClient(read, traversal_limit_in_words=1)
|
||||
|
||||
ref = test_capability_capnp.TestSturdyRefObjectId.new_message(tag='testInterface')
|
||||
with pytest.raises(capnp.KjException):
|
||||
cap = client.restore(ref)
|
||||
cap = cap.cast_as(test_capability_capnp.TestInterface)
|
||||
cap = client.bootstrap().cast_as(test_capability_capnp.TestInterface)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
_ = remote.wait()
|
||||
|
||||
|
||||
def test_simple_rpc_restore_func():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
_ = 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)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '125'
|
||||
|
||||
|
||||
def text_restore_func(objectId):
|
||||
text = objectId.as_text()
|
||||
assert text == 'testInterface'
|
||||
return Server(100)
|
||||
|
||||
|
||||
def test_ez_rpc():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
_ = capnp.TwoPartyServer(write, text_restore_func)
|
||||
client = capnp.TwoPartyClient(read)
|
||||
|
||||
cap = client.ez_restore('testInterface')
|
||||
cap = cap.cast_as(test_capability_capnp.TestInterface)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '125'
|
||||
|
||||
cap = client.restore(test_capability_capnp.TestSturdyRefObjectId.new_message())
|
||||
cap = cap.cast_as(test_capability_capnp.TestInterface)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
|
||||
with pytest.raises(capnp.KjException):
|
||||
response = remote.wait()
|
||||
|
||||
def test_simple_rpc_bootstrap():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
|
||||
@@ -23,7 +23,35 @@ def test_calculator():
|
||||
|
||||
def run_subprocesses(address):
|
||||
server = subprocess.Popen([examples_dir + '/calculator_server.py', address])
|
||||
time.sleep(2) # Give the server some small amount of time to start listening
|
||||
retries = 30
|
||||
if 'unix' in address:
|
||||
addr = address.split(':')[1]
|
||||
while True:
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
result = sock.connect_ex(addr)
|
||||
if result == 0:
|
||||
break
|
||||
# Give the server some small amount of time to start listening
|
||||
time.sleep(0.1)
|
||||
retries -= 1
|
||||
if retries == 0:
|
||||
assert False, "Timed out waiting for server to start"
|
||||
else:
|
||||
addr, port = address.split(':')
|
||||
while True:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
result = sock.connect_ex((addr, int(port)))
|
||||
if result == 0:
|
||||
break
|
||||
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
result = sock.connect_ex((addr, int(port)))
|
||||
if result == 0:
|
||||
break
|
||||
# Give the server some small amount of time to start listening
|
||||
time.sleep(0.1)
|
||||
retries -= 1
|
||||
if retries == 0:
|
||||
assert False, "Timed out waiting for server to start"
|
||||
client = subprocess.Popen([examples_dir + '/calculator_client.py', address])
|
||||
|
||||
ret = client.wait()
|
||||
|
||||
@@ -44,7 +44,7 @@ class Server(test_capability_capnp.TestInterface.Server):
|
||||
'''
|
||||
Server
|
||||
'''
|
||||
def __init__(self, val=1):
|
||||
def __init__(self, val=100):
|
||||
self.val = val
|
||||
|
||||
def foo(self, i, j, **kwargs):
|
||||
@@ -54,19 +54,6 @@ class Server(test_capability_capnp.TestInterface.Server):
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
|
||||
class SimpleRestorer(test_capability_capnp.TestSturdyRefObjectId.Restorer):
|
||||
'''
|
||||
SimpleRestorer
|
||||
'''
|
||||
|
||||
def restore(self, ref_id):
|
||||
'''
|
||||
Restore
|
||||
'''
|
||||
assert ref_id.tag == 'testInterface'
|
||||
return Server(100)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy',
|
||||
reason="pycapnp's GIL handling isn't working properly at the moment for PyPy"
|
||||
@@ -81,8 +68,7 @@ def test_using_threads():
|
||||
read, write = socket.socketpair(socket.AF_UNIX)
|
||||
|
||||
def run_server():
|
||||
restorer = SimpleRestorer()
|
||||
_ = capnp.TwoPartyServer(write, restorer)
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=Server())
|
||||
capnp.wait_forever()
|
||||
|
||||
server_thread = threading.Thread(target=run_server)
|
||||
@@ -90,10 +76,7 @@ def test_using_threads():
|
||||
server_thread.start()
|
||||
|
||||
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)
|
||||
cap = client.bootstrap().cast_as(test_capability_capnp.TestInterface)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
response = remote.wait()
|
||||
|
||||
Reference in New Issue
Block a user