Skip to content

Commit fa80712

Browse files
committed
Added unit-test for error_cb
1 parent 0e7b694 commit fa80712

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_KafkaError.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
3+
from confluent_kafka import Producer, KafkaError, KafkaException
4+
import time
5+
6+
seen_all_brokers_down = False
7+
8+
def error_cb (err):
9+
print('error_cb', err)
10+
if err.code() == KafkaError._ALL_BROKERS_DOWN:
11+
global seen_all_brokers_down
12+
seen_all_brokers_down = True
13+
14+
15+
def test_error_cb():
16+
""" Test the error callback. """
17+
18+
global seen_all_brokers_down
19+
20+
# Configure an invalid broker and make sure the ALL_BROKERS_DOWN
21+
# error is seen in the error callback.
22+
p = Producer({'bootstrap.servers': '127.0.0.1:1', 'socket.timeout.ms':10,
23+
'error_cb': error_cb})
24+
25+
t_end = time.time() + 5
26+
27+
while not seen_all_brokers_down and time.time() < t_end:
28+
p.poll(1)
29+
30+
assert seen_all_brokers_down

0 commit comments

Comments
 (0)