diff options
author | Dana Powers <dana.powers@gmail.com> | 2016-06-18 14:51:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-18 14:51:23 -0700 |
commit | 6271c02c6eebf52a6d368416db49bfa57b09ef04 (patch) | |
tree | 795b70a6c0eb144cd9da6c09f29ff866236734a9 /test | |
parent | 5b9c55817b76eab8346f65e7c973c518d1e82409 (diff) | |
download | kafka-python-6271c02c6eebf52a6d368416db49bfa57b09ef04.tar.gz |
Use weakref when registering a producer.close atexit to fix normal gc (#728)
* Use weakref when registering a producer.close atexit to fix normal gc
* Test that del(producer) terminates async thread
Diffstat (limited to 'test')
-rw-r--r-- | test/test_producer.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/test_producer.py b/test/test_producer.py index f11bb05..125737b 100644 --- a/test/test_producer.py +++ b/test/test_producer.py @@ -1,4 +1,7 @@ +import gc +import platform import sys +import threading import pytest @@ -64,3 +67,14 @@ def test_end_to_end(kafka_broker, compression): break assert msgs == set(['msg %d' % i for i in range(messages)]) + + +@pytest.mark.skipif(platform.python_implementation() != 'CPython', + reason='Test relies on CPython-specific gc policies') +def test_kafka_producer_gc_cleanup(): + threads = threading.active_count() + producer = KafkaProducer(api_version='0.9') # set api_version explicitly to avoid auto-detection + assert threading.active_count() == threads + 1 + del(producer) + gc.collect() + assert threading.active_count() == threads |