Skip to content

Commit

Permalink
Merge pull request #31 from charleswhchan/issue-29
Browse files Browse the repository at this point in the history
Fix #29 - Expose a shutdown() for SerfClient.
  • Loading branch information
KushalP authored Aug 17, 2016
2 parents d5440c1 + 32d91af commit c02a219
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions serfclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ def stats(self):
Obtain operator debugging information about the running Serf agent.
"""
return self.connection.call('stats')

def close(self):
"""
Close connection to Serf agent.
"""
if self.connection:
self.connection.close()
self.connection = None
8 changes: 8 additions & 0 deletions serfclient/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,11 @@ def _decode_addr_key(self, obj_dict):
obj_dict[key] = ip_addr.encode('utf-8')

return obj_dict

def close(self):
"""
Close the connection with the Serf agent.
"""
if self._socket:
self._socket.close()
self._socket = None
5 changes: 5 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ def test_stats_is_well_formed(self, serf):
for key in [b'agent', b'runtime', b'serf', b'tags']:
assert key in stats.body
assert isinstance(stats.body[key], dict)

def test_close(self, serf):
assert serf.connection is not None
serf.close()
assert serf.connection is None
6 changes: 6 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ def test_decode_addr_key_ipv4_mapped_ipv6(self, rpc):
def test_decode_addr_key_ipv4(self, rpc):
ip_address = '192.168.0.1'
assert extract_addr(rpc, ip_address, socket.AF_INET) == ip_address

def test_close(self, rpc):
rpc.handshake()
assert rpc._socket is not None
rpc.close()
assert rpc._socket is None

0 comments on commit c02a219

Please sign in to comment.