Skip to content

Commit

Permalink
Merge pull request #1101 from albertowar/tcp_keep_alive
Browse files Browse the repository at this point in the history
Adding TCP Keep Alive to guarantee master-slave communication after i…
  • Loading branch information
mbeacom authored Oct 1, 2019
2 parents 30f7928 + 3abafce commit c95dda3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions locust/rpc/zmqrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class BaseSocket(object):
def __init__(self, sock_type):
context = zmq.Context()
self.socket = context.socket(sock_type)

self.socket.setsockopt(zmq.TCP_KEEPALIVE, 1)
self.socket.setsockopt(zmq.TCP_KEEPALIVE_IDLE, 30)

@retry()
def send(self, msg):
Expand Down
6 changes: 6 additions & 0 deletions locust/test/test_zmqrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def tearDown(self):
self.server.socket.close()
self.client.socket.close()

def test_constructor(self):
self.assertEqual(self.server.socket.getsockopt(zmq.TCP_KEEPALIVE), 1)
self.assertEqual(self.server.socket.getsockopt(zmq.TCP_KEEPALIVE_IDLE), 30)
self.assertEqual(self.client.socket.getsockopt(zmq.TCP_KEEPALIVE), 1)
self.assertEqual(self.client.socket.getsockopt(zmq.TCP_KEEPALIVE_IDLE), 30)

def test_client_send(self):
self.client.send(Message('test', 'message', 'identity'))
addr, msg = self.server.recv_from_client()
Expand Down

0 comments on commit c95dda3

Please sign in to comment.