Skip to content

Commit 549d8cb

Browse files
committed
Move producer unit test to test/test_producer.py
1 parent 1321f98 commit 549d8cb

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

test/integration/test_producer_integration.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from __future__ import absolute_import
2+
13
from contextlib import contextmanager
2-
import gc
34
import platform
45
import time
5-
import threading
66

77
import pytest
88

@@ -77,18 +77,6 @@ def test_end_to_end(kafka_broker, compression):
7777
assert msgs == set(['msg %d' % (i,) for i in range(messages)])
7878

7979

80-
@pytest.mark.skipif(platform.python_implementation() != 'CPython',
81-
reason='Test relies on CPython-specific gc policies')
82-
def test_kafka_producer_gc_cleanup():
83-
gc.collect()
84-
threads = threading.active_count()
85-
producer = KafkaProducer(api_version=(2, 1)) # set api_version explicitly to avoid auto-detection
86-
assert threading.active_count() == threads + 1
87-
del(producer)
88-
gc.collect()
89-
assert threading.active_count() == threads
90-
91-
9280
@pytest.mark.skipif(not env_kafka_version(), reason="No KAFKA_VERSION set")
9381
@pytest.mark.parametrize("compression", [None, 'gzip', 'snappy', 'lz4', 'zstd'])
9482
def test_kafka_producer_proper_record_metadata(kafka_broker, compression):

test/test_producer.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import absolute_import
2+
3+
import gc
4+
import platform
5+
import threading
6+
7+
import pytest
8+
9+
from kafka import KafkaProducer
10+
11+
@pytest.mark.skipif(platform.python_implementation() != 'CPython',
12+
reason='Test relies on CPython-specific gc policies')
13+
def test_kafka_producer_gc_cleanup():
14+
gc.collect()
15+
threads = threading.active_count()
16+
producer = KafkaProducer(api_version=(2, 1)) # set api_version explicitly to avoid auto-detection
17+
assert threading.active_count() == threads + 1
18+
del(producer)
19+
gc.collect()
20+
assert threading.active_count() == threads
21+
22+
23+

0 commit comments

Comments
 (0)