Skip to content

Commit ecdcdf5

Browse files
author
Dana Powers
committed
(test) Consumer commit() should log errors and return True/False, not raise exceptions
1 parent e60de94 commit ecdcdf5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/test_consumer.py

+24
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ def unknown_topic_partition(request):
8181
with self.assertRaises(UnknownTopicOrPartitionError):
8282
consumer.get_messages(20)
8383

84+
def test_simple_consumer_commit_does_not_raise(self):
85+
client = MagicMock()
86+
client.get_partition_ids_for_topic.return_value = [0, 1]
87+
88+
def mock_offset_fetch_request(group, payloads, **kwargs):
89+
return [OffsetFetchResponse(p.topic, p.partition, 0, b'', 0) for p in payloads]
90+
91+
client.send_offset_fetch_request.side_effect = mock_offset_fetch_request
92+
93+
def mock_offset_commit_request(group, payloads, **kwargs):
94+
raise FailedPayloadsError(payloads[0])
95+
96+
client.send_offset_commit_request.side_effect = mock_offset_commit_request
97+
98+
consumer = SimpleConsumer(client, group='foobar',
99+
topic='topic', partitions=[0, 1],
100+
auto_commit=False)
101+
102+
# Mock internal commit check
103+
consumer.count_since_commit = 10
104+
105+
# This should not raise an exception
106+
self.assertFalse(consumer.commit(partitions=[0, 1]))
107+
84108
@staticmethod
85109
def fail_requests_factory(error_factory):
86110
# Mock so that only the first request gets a valid response

0 commit comments

Comments
 (0)