@@ -47,7 +47,7 @@ def test_group(kafka_broker, topic):
47
47
consumers = {}
48
48
stop = {}
49
49
threads = {}
50
- messages = collections .defaultdict (list )
50
+ messages = collections .defaultdict (lambda : collections . defaultdict ( list ) )
51
51
group_id = 'test-group-' + random_string (6 )
52
52
def consumer_thread (i ):
53
53
assert i not in consumers
@@ -60,15 +60,15 @@ def consumer_thread(i):
60
60
api_version_auto_timeout_ms = 5000 ,
61
61
heartbeat_interval_ms = 500 )
62
62
while not stop [i ].is_set ():
63
- for tp , records in six .itervalues (consumers [i ].poll (timeout_ms = 200 )):
63
+ for tp , records in six .iteritems (consumers [i ].poll (timeout_ms = 200 )):
64
64
messages [i ][tp ].extend (records )
65
- consumers [i ].close ()
65
+ consumers [i ].close (timeout_ms = 500 )
66
66
consumers [i ] = None
67
67
stop [i ] = None
68
68
69
69
num_consumers = 4
70
70
for i in range (num_consumers ):
71
- t = threading .Thread (target = consumer_thread , args = (i ,))
71
+ t = threading .Thread (target = consumer_thread , args = (i ,), daemon = True )
72
72
t .start ()
73
73
threads [i ] = t
74
74
@@ -129,7 +129,8 @@ def consumer_thread(i):
129
129
for c in range (num_consumers ):
130
130
logging .info ('Stopping consumer %s' , c )
131
131
stop [c ].set ()
132
- threads [c ].join ()
132
+ threads [c ].join (timeout = 5 )
133
+ assert not threads [c ].is_alive ()
133
134
threads [c ] = None
134
135
135
136
@@ -179,4 +180,4 @@ def test_heartbeat_thread(kafka_broker, topic):
179
180
assert consumer ._coordinator .heartbeat .last_poll == last_poll
180
181
consumer .poll (timeout_ms = 100 )
181
182
assert consumer ._coordinator .heartbeat .last_poll > last_poll
182
- consumer .close ()
183
+ consumer .close (timeout_ms = 100 )
0 commit comments