summaryrefslogtreecommitdiff
path: root/test/test_client.py
diff options
context:
space:
mode:
authorMark Roberts <wizzat@gmail.com>2014-09-04 12:03:22 -0700
committerMark Roberts <wizzat@gmail.com>2014-09-04 12:03:22 -0700
commit9856cc36d7742922133af0aa53767c8ed4731957 (patch)
tree6641880bd6bf7c899889087b5f11721eaa21f1b2 /test/test_client.py
parenteddd1436c226545237aa057c35719950702466ed (diff)
parent1954f385d15f8d2d8608b13f2c5b175db37d38f8 (diff)
downloadkafka-python-9856cc36d7742922133af0aa53767c8ed4731957.tar.gz
Merge pull request #222 from dpkp/fix_socket_timeout_test
Fix socket timeout test -- mock the side_effect
Diffstat (limited to 'test/test_client.py')
-rw-r--r--test/test_client.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/test_client.py b/test/test_client.py
index 32a2256..6a80bbb 100644
--- a/test/test_client.py
+++ b/test/test_client.py
@@ -1,3 +1,5 @@
+import socket
+from time import sleep
import unittest2
from mock import MagicMock, patch
@@ -6,10 +8,14 @@ from kafka import KafkaClient
from kafka.common import (
ProduceRequest, BrokerMetadata, PartitionMetadata,
TopicAndPartition, KafkaUnavailableError,
- LeaderUnavailableError, PartitionUnavailableError
+ LeaderUnavailableError, PartitionUnavailableError,
+ ConnectionError
)
+from kafka.conn import KafkaConnection
from kafka.protocol import create_message
+from test.testutil import Timer
+
class TestKafkaClient(unittest2.TestCase):
def test_init_with_list(self):
with patch.object(KafkaClient, 'load_metadata_for_topics'):
@@ -242,3 +248,15 @@ class TestKafkaClient(unittest2.TestCase):
with self.assertRaises(LeaderUnavailableError):
client.send_produce_request(requests)
+ def test_timeout(self):
+ def _timeout(*args, **kwargs):
+ timeout = args[1]
+ sleep(timeout)
+ raise socket.timeout
+
+ with patch.object(socket, "create_connection", side_effect=_timeout):
+
+ with Timer() as t:
+ with self.assertRaises(ConnectionError):
+ KafkaConnection("nowhere", 1234, 1.0)
+ self.assertGreaterEqual(t.interval, 1.0)