Skip to content

Commit d8093e6

Browse files
committed
Move test_logger_thread_leaks to CustomLoggingTest
1 parent f672569 commit d8093e6

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

tests/custom_logger_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from unittest import TestCase, main
2222
import asyncio
2323
import logging
24+
import threading
2425
from pulsar import Client
2526

2627
class CustomLoggingTest(TestCase):
@@ -49,6 +50,35 @@ async def async_get(value):
4950

5051
client.close()
5152

53+
def test_logger_thread_leaks(self):
54+
def _do_connect(close):
55+
logger = logging.getLogger(str(threading.current_thread().ident))
56+
logger.setLevel(logging.INFO)
57+
client = Client(
58+
service_url="pulsar://localhost:6650",
59+
io_threads=4,
60+
message_listener_threads=4,
61+
operation_timeout_seconds=1,
62+
log_conf_file_path=None,
63+
authentication=None,
64+
logger=logger,
65+
)
66+
client.get_topic_partitions("persistent://public/default/partitioned_topic_name_test")
67+
if close:
68+
client.close()
69+
70+
for should_close in (True, False):
71+
self.assertEqual(threading.active_count(), 1, "Explicit close: {}; baseline is 1 thread".format(should_close))
72+
_do_connect(should_close)
73+
self.assertEqual(threading.active_count(), 1, "Explicit close: {}; synchronous connect doesn't leak threads".format(should_close))
74+
threads = []
75+
for _ in range(10):
76+
threads.append(threading.Thread(target=_do_connect, args=(should_close)))
77+
threads[-1].start()
78+
for thread in threads:
79+
thread.join()
80+
assert threading.active_count() == 1, "Explicit close: {}; threaded connect in parallel doesn't leak threads".format(should_close)
81+
5282
if __name__ == '__main__':
5383
logging.basicConfig(level=logging.DEBUG)
5484
main()

tests/pulsar_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121

2222
import random
23-
import threading
24-
import logging
2523
from typing import Optional
2624
from unittest import TestCase, main
2725
import time

0 commit comments

Comments
 (0)