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

Commit

Permalink
fix set_timeout only works before TSocket().open()
Browse files Browse the repository at this point in the history
  • Loading branch information
damnever committed Mar 17, 2016
1 parent d8fb4c1 commit 2ff7c42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,27 @@ def test_server_socket_close():

conn.close()
server_socket.close()


def test_client_socket_set_timeout():
server_socket = TServerSocket(host="localhost", port=12345,
client_timeout=100)
server_socket.listen()

client_socket = TSocket(host="localhost", port=12345, socket_timeout=100)
client_socket.open()

conn = server_socket.accept()

assert client_socket.sock.gettimeout() == 100 / 1000
assert conn.sock.gettimeout() == 100 / 1000
assert conn.sock.gettimeout() == 100 / 1000

client_socket.set_timeout(200)
conn.set_timeout(200)
assert client_socket.sock.gettimeout() == 200 / 1000
assert conn.sock.gettimeout() == 200 / 1000

conn.close()
client_socket.close()
server_socket.close()
3 changes: 3 additions & 0 deletions thriftpy/transport/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def set_timeout(self, ms):
self.socket_timeout = ms / 1000 if (ms and ms > 0) else None
self.connect_timeout = self.socket_timeout

if self.sock is not None:
self.sock.settimeout(self.socket_timeout)

def is_open(self):
return bool(self.sock)

Expand Down

0 comments on commit 2ff7c42

Please sign in to comment.