Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Virtual transport timeout does not supesede period polling (#689)
fixes #688
  • Loading branch information
arcivanov authored and auvipy committed Jan 13, 2018
1 parent e209fa6 commit 2f9eb53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -144,3 +144,4 @@ Vincent Driessen <vincent@datafox.nl>
Wido den Hollander <wido@widodh.nl>
Zach Smith <zmsmith27@gmail.com>
Zhao Xiaohong <mrluanma@gmail.com>
Arcadiy Ivanov <arcadiy@ivanov.biz>
2 changes: 2 additions & 0 deletions kombu/transport/virtual/base.py
Expand Up @@ -956,6 +956,8 @@ def drain_events(self, connection, timeout=None):
time_start = monotonic()
get = self.cycle.get
polling_interval = self.polling_interval
if timeout and polling_interval and polling_interval > timeout:
polling_interval = timeout
while 1:
try:
get(self._deliver, timeout=timeout)
Expand Down
9 changes: 9 additions & 0 deletions t/unit/transport/virtual/test_base.py
Expand Up @@ -4,6 +4,7 @@
import pytest
import sys
import warnings
import socket

from case import MagicMock, Mock, patch

Expand All @@ -12,6 +13,7 @@
from kombu.exceptions import ResourceError, ChannelError
from kombu.transport import virtual
from kombu.utils.uuid import uuid
from kombu.five import monotonic

PY3 = sys.version_info[0] == 3
PRINT_FQDN = 'builtins.print' if PY3 else '__builtin__.print'
Expand Down Expand Up @@ -556,6 +558,13 @@ def test_custom_polling_interval(self):
x = client(transport_options={'polling_interval': 32.3})
assert x.transport.polling_interval == 32.3

def test_timeout_over_polling_interval(self):
x = client(transport_options=dict(polling_interval=60))
start = monotonic()
with pytest.raises(socket.timeout):
x.transport.drain_events(x, timeout=.5)
assert monotonic() - start < 60

def test_close_connection(self):
c1 = self.transport.create_channel(self.transport)
c2 = self.transport.create_channel(self.transport)
Expand Down

0 comments on commit 2f9eb53

Please sign in to comment.