Disable option to run capnp without asyncio

This commit is contained in:
Lasse Blaauwbroek
2023-06-08 02:27:38 +02:00
parent 6e011cfe78
commit 97bdeaea12
15 changed files with 70 additions and 726 deletions

View File

@@ -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