Skip to content
Snippets Groups Projects
Commit 30ab143c1921 authored by Luke Bakken's avatar Luke Bakken
Browse files

Pika heartbeat sending and checking now behaves exactly as the Java client

parent 31d2d01280b9
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
this value by dividing it by two. this value by dividing it by two.
""" """
if timeout < 1:
raise ValueError('timeout must >= 0, but got %r' % (timeout,))
self._connection = connection self._connection = connection
# Note: see the following documents: # Note: see the following documents:
...@@ -46,4 +49,5 @@ ...@@ -46,4 +49,5 @@
# heartbeat. This is to avoid edge cases and not to depend on network # heartbeat. This is to avoid edge cases and not to depend on network
# latency. # latency.
self._timeout = timeout self._timeout = timeout
self._send_interval = float(timeout) / 2 self._send_interval = float(timeout) / 2
...@@ -49,5 +53,16 @@ ...@@ -49,5 +53,16 @@
self._send_interval = float(timeout) / 2 self._send_interval = float(timeout) / 2
self._check_interval = timeout
# Note: Pika doubles the negotiated timeout to match the behavior of the
# RabbitMQ Java client and the spec that suggests a check interval equivalent
# to two times the heartbeat timeout value.
# https://github.com/pika/pika/pull/1072#issuecomment-397850795
# https://github.com/rabbitmq/rabbitmq-java-client/blob/b55bd20a1a236fc2d1ea9369b579770fa0237615/src/main/java/com/rabbitmq/client/impl/AMQConnection.java#L773-L780
self._check_interval = float(timeout) * 2;
LOGGER.debug('timeout: %f send_interval: %f check_interval: %f',
self._timeout,
self._send_interval,
self._check_interval)
# Initialize counters # Initialize counters
self._bytes_received = 0 self._bytes_received = 0
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
INTERVAL = 60 INTERVAL = 60
SEND_INTERVAL = float(INTERVAL) / 2 SEND_INTERVAL = float(INTERVAL) / 2
CHECK_INTERVAL = INTERVAL CHECK_INTERVAL = float(INTERVAL) * 2
def setUp(self): def setUp(self):
self.mock_conn = mock.Mock(spec=connection.Connection) self.mock_conn = mock.Mock(spec=connection.Connection)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment