Skip to content

Commit 32aec02

Browse files
author
Roberto Gandolfo Hashioka
committed
Merge pull request #2 from docker-hub/race-condition-test-fix
fixing the unit test race condition
2 parents b09969e + e5aea18 commit 32aec02

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/test_producer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from queue import Full
77
except ImportError:
88
from Queue import Full
9-
from mock import MagicMock
9+
from mock import MagicMock, patch
1010
from . import unittest
11-
11+
from six.moves import xrange
1212
from kafka.producer.base import Producer
1313

1414

@@ -45,7 +45,8 @@ def partitions(topic):
4545
producer.send_messages(topic, b'hi')
4646
assert client.send_produce_request.called
4747

48-
def test_producer_async_queue_overfilled_batch_send(self):
48+
@patch('kafka.producer.base._send_upstream')
49+
def test_producer_async_queue_overfilled_batch_send(self, mock):
4950
queue_size = 2
5051
producer = Producer(MagicMock(), batch_send=True, maxsize=queue_size)
5152

@@ -57,6 +58,8 @@ def test_producer_async_queue_overfilled_batch_send(self):
5758
message_list = [message] * (queue_size + 1)
5859
producer.send_messages(topic, partition, *message_list)
5960
self.assertEqual(producer.queue.qsize(), queue_size)
61+
for _ in xrange(producer.queue.qsize()):
62+
producer.queue.get()
6063

6164
def test_producer_async_queue_overfilled(self):
6265
queue_size = 2

0 commit comments

Comments
 (0)