Disable option to run capnp without asyncio
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
import time
|
||||
|
||||
import capnp
|
||||
import test_capability_capnp as capability
|
||||
@@ -32,7 +31,7 @@ class PipelineServer(capability.TestPipeline.Server):
|
||||
return inCap.foo(i=n).then(_then)
|
||||
|
||||
|
||||
def test_client():
|
||||
async def test_client():
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
req = client._request("foo")
|
||||
@@ -65,7 +64,7 @@ def test_client():
|
||||
req.baz = 1
|
||||
|
||||
|
||||
def test_simple_client():
|
||||
async def test_simple_client():
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
remote = client._send("foo", i=5)
|
||||
@@ -125,7 +124,7 @@ def test_simple_client():
|
||||
remote = client.foo(baz=5)
|
||||
|
||||
|
||||
def test_pipeline():
|
||||
async def test_pipeline():
|
||||
client = capability.TestPipeline._new_client(PipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(Server())
|
||||
|
||||
@@ -152,7 +151,7 @@ class BadServer(capability.TestInterface.Server):
|
||||
return str(i * 5 + extra + self.val), 10 # returning too many args
|
||||
|
||||
|
||||
def test_exception_client():
|
||||
async def test_exception_client():
|
||||
client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
remote = client._send("foo", i=5)
|
||||
@@ -173,7 +172,7 @@ class BadPipelineServer(capability.TestPipeline.Server):
|
||||
return inCap.foo(i=n).then(_then, _error)
|
||||
|
||||
|
||||
def test_exception_chain():
|
||||
async def test_exception_chain():
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
@@ -185,7 +184,7 @@ def test_exception_chain():
|
||||
assert "test was a success" in str(e)
|
||||
|
||||
|
||||
def test_pipeline_exception():
|
||||
async def test_pipeline_exception():
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
@@ -201,7 +200,7 @@ def test_pipeline_exception():
|
||||
remote.wait()
|
||||
|
||||
|
||||
def test_casting():
|
||||
async def test_casting():
|
||||
client = capability.TestExtends._new_client(Server())
|
||||
client2 = client.upcast(capability.TestInterface)
|
||||
_ = client2.cast_as(capability.TestInterface)
|
||||
@@ -243,7 +242,7 @@ class TailCallee(capability.TestTailCallee.Server):
|
||||
results.c = TailCallOrder()
|
||||
|
||||
|
||||
def test_tail_call():
|
||||
async def test_tail_call():
|
||||
callee_server = TailCallee()
|
||||
caller_server = TailCaller()
|
||||
|
||||
@@ -272,7 +271,7 @@ def test_tail_call():
|
||||
assert caller_server.count == 1
|
||||
|
||||
|
||||
def test_cancel():
|
||||
async def test_cancel():
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
req = client._request("foo")
|
||||
@@ -300,7 +299,7 @@ def test_cancel():
|
||||
req.wait()
|
||||
|
||||
|
||||
def test_double_send():
|
||||
async def test_double_send():
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
req = client._request("foo")
|
||||
@@ -311,7 +310,7 @@ def test_double_send():
|
||||
req.send()
|
||||
|
||||
|
||||
def test_then_args():
|
||||
async def test_then_args():
|
||||
capnp.Promise(0).then(lambda x: 1)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
@@ -350,7 +349,7 @@ class PromiseJoinServer(capability.TestPipeline.Server):
|
||||
)
|
||||
|
||||
|
||||
def test_promise_joining():
|
||||
async def test_promise_joining():
|
||||
client = capability.TestPipeline._new_client(PromiseJoinServer())
|
||||
foo_client = capability.TestInterface._new_client(Server())
|
||||
|
||||
@@ -363,7 +362,7 @@ class ExtendsServer(Server):
|
||||
pass
|
||||
|
||||
|
||||
def test_inheritance():
|
||||
async def test_inheritance():
|
||||
client = capability.TestExtends._new_client(ExtendsServer())
|
||||
client.qux().wait()
|
||||
|
||||
@@ -381,7 +380,7 @@ class PassedCapTest(capability.TestPassedCap.Server):
|
||||
return cap.foo(5).then(set_result)
|
||||
|
||||
|
||||
def test_null_cap():
|
||||
async def test_null_cap():
|
||||
client = capability.TestPassedCap._new_client(PassedCapTest())
|
||||
assert client.foo(Server()).wait().x == "26"
|
||||
|
||||
@@ -394,7 +393,7 @@ class StructArgTest(capability.TestStructArg.Server):
|
||||
return a + str(b)
|
||||
|
||||
|
||||
def test_struct_args():
|
||||
async def test_struct_args():
|
||||
client = capability.TestStructArg._new_client(StructArgTest())
|
||||
assert client.bar(a="test", b=1).wait().c == "test1"
|
||||
with pytest.raises(capnp.KjException):
|
||||
@@ -406,7 +405,7 @@ class GenericTest(capability.TestGeneric.Server):
|
||||
return a.as_text() + "test"
|
||||
|
||||
|
||||
def test_generic():
|
||||
async def test_generic():
|
||||
client = capability.TestGeneric._new_client(GenericTest())
|
||||
|
||||
obj = capnp._MallocMessageBuilder().get_root_as_any()
|
||||
|
||||
@@ -39,7 +39,7 @@ class PipelineServer:
|
||||
return context.params.inCap.foo(i=context.params.n).then(_then)
|
||||
|
||||
|
||||
def test_client_context(capability):
|
||||
async def test_client_context(capability):
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
req = client._request("foo")
|
||||
@@ -72,7 +72,7 @@ def test_client_context(capability):
|
||||
req.baz = 1
|
||||
|
||||
|
||||
def test_simple_client_context(capability):
|
||||
async def test_simple_client_context(capability):
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
remote = client._send("foo", i=5)
|
||||
@@ -159,7 +159,7 @@ class BadServer:
|
||||
context.results.x2 = 5 # raises exception
|
||||
|
||||
|
||||
def test_exception_client_context(capability):
|
||||
async def test_exception_client_context(capability):
|
||||
client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
remote = client._send("foo", i=5)
|
||||
@@ -181,7 +181,7 @@ class BadPipelineServer:
|
||||
return context.params.inCap.foo(i=context.params.n).then(_then, _error)
|
||||
|
||||
|
||||
def test_exception_chain_context(capability):
|
||||
async def test_exception_chain_context(capability):
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
@@ -193,7 +193,7 @@ def test_exception_chain_context(capability):
|
||||
assert "test was a success" in str(e)
|
||||
|
||||
|
||||
def test_pipeline_exception_context(capability):
|
||||
async def test_pipeline_exception_context(capability):
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
@@ -209,7 +209,7 @@ def test_pipeline_exception_context(capability):
|
||||
remote.wait()
|
||||
|
||||
|
||||
def test_casting_context(capability):
|
||||
async def test_casting_context(capability):
|
||||
client = capability.TestExtends._new_client(Server())
|
||||
client2 = client.upcast(capability.TestInterface)
|
||||
_ = client2.cast_as(capability.TestInterface)
|
||||
|
||||
@@ -37,7 +37,7 @@ class PipelineServer:
|
||||
return inCap.foo(i=n).then(_then)
|
||||
|
||||
|
||||
def test_client(capability):
|
||||
async def test_client(capability):
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
req = client._request("foo")
|
||||
@@ -70,7 +70,7 @@ def test_client(capability):
|
||||
req.baz = 1
|
||||
|
||||
|
||||
def test_simple_client(capability):
|
||||
async def test_simple_client(capability):
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
remote = client._send("foo", i=5)
|
||||
@@ -159,7 +159,7 @@ class BadServer:
|
||||
return str(i * 5 + extra + self.val), 10 # returning too many args
|
||||
|
||||
|
||||
def test_exception_client(capability):
|
||||
async def test_exception_client(capability):
|
||||
client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
remote = client._send("foo", i=5)
|
||||
@@ -180,7 +180,7 @@ class BadPipelineServer:
|
||||
return inCap.foo(i=n).then(_then, _error)
|
||||
|
||||
|
||||
def test_exception_chain(capability):
|
||||
async def test_exception_chain(capability):
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
@@ -192,7 +192,7 @@ def test_exception_chain(capability):
|
||||
assert "test was a success" in str(e)
|
||||
|
||||
|
||||
def test_pipeline_exception(capability):
|
||||
async def test_pipeline_exception(capability):
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
@@ -208,7 +208,7 @@ def test_pipeline_exception(capability):
|
||||
remote.wait()
|
||||
|
||||
|
||||
def test_casting(capability):
|
||||
async def test_casting(capability):
|
||||
client = capability.TestExtends._new_client(Server())
|
||||
client2 = client.upcast(capability.TestInterface)
|
||||
_ = client2.cast_as(capability.TestInterface)
|
||||
|
||||
@@ -124,16 +124,6 @@ def test_async_calculator_example(cleanup):
|
||||
run_subprocesses(address, server, client)
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="Some versions of python don't like to share ports, don't worry if this fails"
|
||||
)
|
||||
def test_thread_example(cleanup):
|
||||
address = "{}:36433".format(hostname)
|
||||
server = "thread_server.py"
|
||||
client = "thread_client.py"
|
||||
run_subprocesses(address, server, client, wildcard_server=True)
|
||||
|
||||
|
||||
def test_addressbook_example(cleanup):
|
||||
proc = subprocess.Popen(
|
||||
[sys.executable, os.path.join(examples_dir, "addressbook.py")]
|
||||
|
||||
@@ -17,7 +17,7 @@ class BazServer(test_response_capnp.Baz.Server):
|
||||
return {"foo": FooServer()}
|
||||
|
||||
|
||||
def test_response_reference():
|
||||
async def test_response_reference():
|
||||
baz = test_response_capnp.Baz._new_client(BazServer())
|
||||
|
||||
bar = baz.grault().wait().bar
|
||||
@@ -27,7 +27,7 @@ def test_response_reference():
|
||||
assert foo.foo().wait().val == 1
|
||||
|
||||
|
||||
def test_response_reference2():
|
||||
async def test_response_reference2():
|
||||
baz = test_response_capnp.Baz._new_client(BazServer())
|
||||
|
||||
bar = baz.grault().wait().bar
|
||||
|
||||
@@ -17,8 +17,10 @@ class Server(test_capability_capnp.TestInterface.Server):
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
|
||||
def test_simple_rpc_with_options():
|
||||
async def test_simple_rpc_with_options():
|
||||
read, write = socket.socketpair()
|
||||
read = await capnp.AsyncIoStream.create_connection(sock = read)
|
||||
write = await capnp.AsyncIoStream.create_connection(sock = write)
|
||||
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=Server())
|
||||
# This traversal limit is too low to receive the response in, so we expect
|
||||
@@ -32,8 +34,10 @@ def test_simple_rpc_with_options():
|
||||
_ = remote.wait()
|
||||
|
||||
|
||||
def test_simple_rpc_bootstrap():
|
||||
async def test_simple_rpc_bootstrap():
|
||||
read, write = socket.socketpair()
|
||||
read = await capnp.AsyncIoStream.create_connection(sock = read)
|
||||
write = await capnp.AsyncIoStream.create_connection(sock = write)
|
||||
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=Server(100))
|
||||
client = capnp.TwoPartyClient(read)
|
||||
@@ -42,6 +46,6 @@ def test_simple_rpc_bootstrap():
|
||||
cap = cap.cast_as(test_capability_capnp.TestInterface)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
response = remote.wait()
|
||||
response = await remote
|
||||
|
||||
assert response.x == "125"
|
||||
|
||||
@@ -9,57 +9,20 @@ import capnp
|
||||
examples_dir = os.path.join(os.path.dirname(__file__), "..", "examples")
|
||||
sys.path.append(examples_dir)
|
||||
|
||||
import calculator_client # noqa: E402
|
||||
import calculator_server # noqa: E402
|
||||
|
||||
# Uses run_subprocesses function
|
||||
import test_examples # noqa: E402
|
||||
|
||||
processes = []
|
||||
import async_calculator_client # noqa: E402
|
||||
import async_calculator_server # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cleanup():
|
||||
yield
|
||||
for p in processes:
|
||||
p.kill()
|
||||
|
||||
|
||||
def test_calculator():
|
||||
async def test_calculator():
|
||||
read, write = socket.socketpair()
|
||||
read = await capnp.AsyncIoStream.create_connection(sock = read)
|
||||
write = await capnp.AsyncIoStream.create_connection(sock = write)
|
||||
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=calculator_server.CalculatorImpl())
|
||||
calculator_client.main(read)
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=async_calculator_server.CalculatorImpl())
|
||||
await async_calculator_client.main(read)
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="Some versions of python don't like to share ports, don't worry if this fails"
|
||||
)
|
||||
def test_calculator_tcp(cleanup):
|
||||
address = "localhost:36431"
|
||||
test_examples.run_subprocesses(
|
||||
address, "calculator_server.py", "calculator_client.py", wildcard_server=True
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="Some versions of python don't like to share ports, don't worry if this fails"
|
||||
)
|
||||
@pytest.mark.skipif(os.name == "nt", reason="socket.AF_UNIX not supported on Windows")
|
||||
def test_calculator_unix(cleanup):
|
||||
path = "/tmp/pycapnp-test"
|
||||
try:
|
||||
os.unlink(path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
address = "unix:" + path
|
||||
test_examples.run_subprocesses(
|
||||
address, "calculator_server.py", "calculator_client.py"
|
||||
)
|
||||
|
||||
|
||||
def test_calculator_gc():
|
||||
async def test_calculator_gc():
|
||||
def new_evaluate_impl(old_evaluate_impl):
|
||||
def call(*args, **kwargs):
|
||||
gc.collect()
|
||||
@@ -68,12 +31,14 @@ def test_calculator_gc():
|
||||
return call
|
||||
|
||||
read, write = socket.socketpair()
|
||||
read = await capnp.AsyncIoStream.create_connection(sock = read)
|
||||
write = await capnp.AsyncIoStream.create_connection(sock = write)
|
||||
|
||||
# inject a gc.collect to the beginning of every evaluate_impl call
|
||||
evaluate_impl_orig = calculator_server.evaluate_impl
|
||||
calculator_server.evaluate_impl = new_evaluate_impl(evaluate_impl_orig)
|
||||
evaluate_impl_orig = async_calculator_server.evaluate_impl
|
||||
async_calculator_server.evaluate_impl = new_evaluate_impl(evaluate_impl_orig)
|
||||
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=calculator_server.CalculatorImpl())
|
||||
calculator_client.main(read)
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=async_calculator_server.CalculatorImpl())
|
||||
await async_calculator_client.main(read)
|
||||
|
||||
calculator_server.evaluate_impl = evaluate_impl_orig
|
||||
async_calculator_server.evaluate_impl = evaluate_impl_orig
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
"""
|
||||
thread test
|
||||
"""
|
||||
|
||||
import platform
|
||||
import socket
|
||||
import threading
|
||||
|
||||
import pytest
|
||||
|
||||
import capnp
|
||||
|
||||
import test_capability_capnp
|
||||
|
||||
|
||||
class Server(test_capability_capnp.TestInterface.Server):
|
||||
"""
|
||||
Server
|
||||
"""
|
||||
|
||||
def __init__(self, val=100):
|
||||
self.val = val
|
||||
|
||||
def foo(self, i, j, **kwargs):
|
||||
"""
|
||||
foo
|
||||
"""
|
||||
return str(i * 5 + self.val)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == "PyPy",
|
||||
reason="pycapnp's GIL handling isn't working properly at the moment for PyPy",
|
||||
)
|
||||
def test_using_threads():
|
||||
"""
|
||||
Thread test
|
||||
"""
|
||||
read, write = socket.socketpair()
|
||||
|
||||
def run_server():
|
||||
_ = capnp.TwoPartyServer(write, bootstrap=Server())
|
||||
capnp.wait_forever()
|
||||
|
||||
server_thread = threading.Thread(target=run_server)
|
||||
server_thread.daemon = True
|
||||
server_thread.start()
|
||||
|
||||
client = capnp.TwoPartyClient(read)
|
||||
cap = client.bootstrap().cast_as(test_capability_capnp.TestInterface)
|
||||
|
||||
remote = cap.foo(i=5)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == "125"
|
||||
Reference in New Issue
Block a user