Add support for unix sockets and improve rpc testing
This commit is contained in:
@@ -2204,13 +2204,18 @@ cdef class TwoPartyClient:
|
|||||||
del self.thisptr
|
del self.thisptr
|
||||||
|
|
||||||
cpdef _connect(self, host_string):
|
cpdef _connect(self, host_string):
|
||||||
host, port = host_string.split(':')
|
if host_string.startswith('unix:'):
|
||||||
|
path = host_string[5:]
|
||||||
|
sock = _socket.socket(_socket.AF_UNIX, _socket.SOCK_STREAM)
|
||||||
|
sock.connect(path)
|
||||||
|
else:
|
||||||
|
host, port = host_string.split(':')
|
||||||
|
|
||||||
sock = _socket.create_connection((host, port))
|
sock = _socket.create_connection((host, port))
|
||||||
|
|
||||||
# Set TCP_NODELAY on socket to disable Nagle's algorithm. This is not
|
# Set TCP_NODELAY on socket to disable Nagle's algorithm. This is not
|
||||||
# neccessary, but it speeds things up.
|
# neccessary, but it speeds things up.
|
||||||
sock.setsockopt(_socket.IPPROTO_TCP, _socket.TCP_NODELAY, 1)
|
sock.setsockopt(_socket.IPPROTO_TCP, _socket.TCP_NODELAY, 1)
|
||||||
return sock
|
return sock
|
||||||
|
|
||||||
cpdef restore(self, objectId) except +reraise_kj_exception:
|
cpdef restore(self, objectId) except +reraise_kj_exception:
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ import capnp
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import gc
|
import gc
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
import sys # add examples dir to sys.path
|
import sys # add examples dir to sys.path
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'examples'))
|
examples_dir = os.path.join(os.path.dirname(__file__), '..', 'examples')
|
||||||
|
sys.path.append(examples_dir)
|
||||||
import calculator_client
|
import calculator_client
|
||||||
import calculator_server
|
import calculator_server
|
||||||
|
|
||||||
@@ -16,6 +19,31 @@ def test_calculator():
|
|||||||
calculator_client.main(read)
|
calculator_client.main(read)
|
||||||
|
|
||||||
|
|
||||||
|
def run_subprocesses(address):
|
||||||
|
server = subprocess.Popen([examples_dir + '/calculator_server.py', address])
|
||||||
|
time.sleep(.1) # Give the server some small amount of time to start listening
|
||||||
|
client = subprocess.Popen([examples_dir + '/calculator_client.py', address])
|
||||||
|
|
||||||
|
ret = client.wait()
|
||||||
|
server.kill()
|
||||||
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_calculator_tcp():
|
||||||
|
address = '127.0.0.1:36431'
|
||||||
|
run_subprocesses(address)
|
||||||
|
|
||||||
|
|
||||||
|
def test_calculator_unix():
|
||||||
|
path = '/tmp/pycapnp-test'
|
||||||
|
try:
|
||||||
|
os.unlink(path)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
address = 'unix:' + path
|
||||||
|
run_subprocesses(address)
|
||||||
|
|
||||||
def test_calculator_gc():
|
def test_calculator_gc():
|
||||||
def new_evaluate_impl(old_evaluate_impl):
|
def new_evaluate_impl(old_evaluate_impl):
|
||||||
def call(*args, **kwargs):
|
def call(*args, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user