Skip to content

Commit c02a219

Browse files
authored
Merge pull request #31 from charleswhchan/issue-29
Fix #29 - Expose a shutdown() for SerfClient.
2 parents d5440c1 + 32d91af commit c02a219

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

serfclient/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ def stats(self):
7474
Obtain operator debugging information about the running Serf agent.
7575
"""
7676
return self.connection.call('stats')
77+
78+
def close(self):
79+
"""
80+
Close connection to Serf agent.
81+
"""
82+
if self.connection:
83+
self.connection.close()
84+
self.connection = None

serfclient/connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,11 @@ def _decode_addr_key(self, obj_dict):
166166
obj_dict[key] = ip_addr.encode('utf-8')
167167

168168
return obj_dict
169+
170+
def close(self):
171+
"""
172+
Close the connection with the Serf agent.
173+
"""
174+
if self._socket:
175+
self._socket.close()
176+
self._socket = None

tests/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ def test_stats_is_well_formed(self, serf):
110110
for key in [b'agent', b'runtime', b'serf', b'tags']:
111111
assert key in stats.body
112112
assert isinstance(stats.body[key], dict)
113+
114+
def test_close(self, serf):
115+
assert serf.connection is not None
116+
serf.close()
117+
assert serf.connection is None

tests/test_connection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ def test_decode_addr_key_ipv4_mapped_ipv6(self, rpc):
134134
def test_decode_addr_key_ipv4(self, rpc):
135135
ip_address = '192.168.0.1'
136136
assert extract_addr(rpc, ip_address, socket.AF_INET) == ip_address
137+
138+
def test_close(self, rpc):
139+
rpc.handshake()
140+
assert rpc._socket is not None
141+
rpc.close()
142+
assert rpc._socket is None

0 commit comments

Comments
 (0)