Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #140 from maralla/unix_socket
Browse files Browse the repository at this point in the history
fix unix socket in tests
  • Loading branch information
lxyu committed Jun 18, 2015
2 parents 193c752 + 3cedc9e commit 5319ad2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/test_multiplexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

mux = thriftpy.load(os.path.join(os.path.dirname(__file__),
"multiplexed.thrift"))
sock_path = "./thriftpy_test.sock"
sock_path = "/tmp/thriftpy_test.sock"


class DispatcherOne(object):
Expand Down
12 changes: 8 additions & 4 deletions tests/test_protocol_cybinary.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,29 +297,33 @@ def test_skip_struct():
def test_read_long_data():
val = 'z' * 97 * 1024

unix_sock = "/tmp/thriftpy_test.sock"

def serve():
server_sock = TServerSocket(
unix_socket="./thriftpy_test.sock")
server_sock = TServerSocket(unix_socket=unix_sock)
server_sock.listen()
client = server_sock.accept()
t = TCyBufferedTransport(client)
proto.write_val(t, TType.STRING, val)
t.flush()

# wait for client to read
time.sleep(1)

p = multiprocessing.Process(target=serve)
p.start()
time.sleep(0.1)

try:
sock = TSocket(unix_socket="./thriftpy_test.sock")
sock = TSocket(unix_socket=unix_sock)
b = TCyBufferedTransport(sock)
b.open()
assert val == proto.read_val(b, TType.STRING)
sock.close()
finally:
p.terminate()
try:
os.remove("./thriftpy_test.sock")
os.remove(unix_sock)
except IOError:
pass

Expand Down
8 changes: 4 additions & 4 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

addressbook = thriftpy.load(os.path.join(os.path.dirname(__file__),
"addressbook.thrift"))
unix_sock = "/tmp/thriftpy_test.sock"


class Dispatcher(object):
Expand Down Expand Up @@ -68,7 +69,7 @@ def sleep(self, ms):
@pytest.fixture(scope="module")
def server(request):
server = make_server(addressbook.AddressBookService, Dispatcher(),
unix_socket="./thriftpy_test.sock")
unix_socket=unix_sock)
ps = multiprocessing.Process(target=server.serve)
ps.start()

Expand All @@ -78,7 +79,7 @@ def fin():
if ps.is_alive():
ps.terminate()
try:
os.remove("./thriftpy_test.sock")
os.remove(unix_sock)
except IOError:
pass
request.addfinalizer(fin)
Expand Down Expand Up @@ -106,8 +107,7 @@ def person():

def client(timeout=3000):
return client_context(addressbook.AddressBookService,
unix_socket="./thriftpy_test.sock",
timeout=timeout)
unix_socket=unix_sock, timeout=timeout)


def test_void_api(server):
Expand Down

0 comments on commit 5319ad2

Please sign in to comment.