@@ -74,7 +74,8 @@ def test_switch_leader(self):
7474 self ._send_random_messages (producer , topic , partition , 10 )
7575
7676 # count number of messages
77- count = self ._count_messages ('test_switch_leader group' , topic , partition )
77+ count = self ._count_messages ('test_switch_leader group' , topic ,
78+ partitions = (partition ,))
7879
7980 # Should be equal to 10 before + 1 recovery + 10 after
8081 self .assertEquals (count , 21 )
@@ -108,7 +109,8 @@ def test_switch_leader_async(self):
108109 producer .stop ()
109110
110111 # count number of messages
111- count = self ._count_messages ('test_switch_leader_async group' , topic , partition )
112+ count = self ._count_messages ('test_switch_leader_async group' , topic ,
113+ partitions = (partition ,))
112114
113115 # Should be equal to 10 before + 1 recovery + 10 after
114116 self .assertEquals (count , 21 )
@@ -128,18 +130,17 @@ def _kill_leader(self, topic, partition):
128130 broker .close ()
129131 return broker
130132
131- def _count_messages (self , group , topic , timeout = 1 ):
133+ def _count_messages (self , group , topic , timeout = 1 , partitions = None ):
132134 hosts = ',' .join (['%s:%d' % (broker .host , broker .port )
133135 for broker in self .brokers ])
134136
135137 client = KafkaClient (hosts )
136138 consumer = SimpleConsumer (client , group , topic ,
139+ partitions = partitions ,
137140 auto_commit = False ,
138141 iter_timeout = timeout )
139142
140- all_messages = []
141- for message in consumer :
142- all_messages .append (message )
143+ count = consumer .pending (partitions )
143144 consumer .stop ()
144145 client .close ()
145- return len ( all_messages )
146+ return count
0 commit comments