X Tutup
Skip to content

Commit a814e9d

Browse files
committed
make sure to stop conpool between sensitive unitests
1 parent d37b6d6 commit a814e9d

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

telegram/utils/request.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ def _get_con_pool():
4949
])
5050
return _CON_POOL
5151

52+
5253
def is_con_pool_initialized():
5354
return _CON_POOL is not None
5455

5556

57+
def stop_con_pool():
58+
global _CON_POOL
59+
if _CON_POOL is not None:
60+
_CON_POOL.close()
61+
_CON_POOL = None
62+
63+
64+
5665
def _parse(json_data):
5766
"""Try and parse the JSON returned from Telegram.
5867

tests/test_jobqueue.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#!/usr/bin/env python
23
# encoding: utf-8
34
#
@@ -31,6 +32,7 @@
3132

3233
sys.path.append('.')
3334

35+
from telegram.utils.request import stop_con_pool
3436
from telegram.ext import JobQueue, Updater
3537
from tests.base import BaseTest
3638

@@ -58,6 +60,7 @@ def setUp(self):
5860
def tearDown(self):
5961
if self.jq is not None:
6062
self.jq.stop()
63+
stop_con_pool()
6164

6265
def job1(self, bot):
6366
self.result += 1

tests/test_updater.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
sys.path.append('.')
4949

5050
from telegram import Update, Message, TelegramError, User, Chat, Bot
51+
from telegram.utils.request import stop_con_pool
5152
from telegram.ext import *
5253
from telegram.ext.dispatcher import run_async
5354
from telegram.error import Unauthorized, InvalidToken
@@ -84,6 +85,7 @@ def _setup_updater(self, *args, **kwargs):
8485
def tearDown(self):
8586
if self.updater is not None:
8687
self.updater.stop()
88+
stop_con_pool()
8789

8890
def reset(self):
8991
self.message_count = 0

0 commit comments

Comments
 (0)
X Tutup