Merge "Correctly set socket timeout for publishing"

This commit is contained in:
Jenkins 2016-02-11 13:21:40 +00:00 committed by Gerrit Code Review
commit fafe97709c
2 changed files with 13 additions and 3 deletions

View File

@ -810,7 +810,17 @@ class Connection(object):
# or the producer.send return only when the system socket
# timeout if reach. kombu doesn't allow use to customise this
# timeout so for py-amqp we tweak ourself
sock = getattr(self.connection.transport, 'sock', None)
# NOTE(dmitryme): Current approach works with amqp==1.4.9 and
# kombu==3.0.33. Once the commit below is released, we should
# try to set the socket timeout in the constructor:
# https://github.com/celery/py-amqp/pull/64
try:
sock = self.channel.connection.sock
except AttributeError as e:
# Level is set to debug because otherwise we would spam the logs
LOG.debug('Failed to get socket attribute: %s' % str(e))
sock = None
if sock:
orig_timeout = sock.gettimeout()
sock.settimeout(timeout)

View File

@ -90,11 +90,11 @@ class TestHeartbeat(test_utils.BaseTestCase):
if not heartbeat_side_effect:
self.assertEqual(1, fake_ensure_connection.call_count)
self.assertEqual(2, fake_logger.debug.call_count)
self.assertEqual(3, fake_logger.debug.call_count)
self.assertEqual(0, fake_logger.info.call_count)
else:
self.assertEqual(2, fake_ensure_connection.call_count)
self.assertEqual(2, fake_logger.debug.call_count)
self.assertEqual(3, fake_logger.debug.call_count)
self.assertEqual(1, fake_logger.info.call_count)
self.assertIn(mock.call(info, mock.ANY),
fake_logger.info.mock_calls)