Skip to content

Commit b2af6b0

Browse files
committed
Strict tests: fail on any unexpected call of loop.call_exception_handler
1 parent ac77939 commit b2af6b0

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

tests/test_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ async def foo():
370370
self.assertIn('test_debug_slow_task_callbacks', msg)
371371

372372
def test_default_exc_handler_callback(self):
373+
self.loop.set_exception_handler(None)
374+
373375
self.loop._process_events = mock.Mock()
374376

375377
def zero_error(fut):
@@ -399,6 +401,7 @@ def zero_error(fut):
399401
exc_info=mock.ANY)
400402

401403
def test_set_exc_handler_custom(self):
404+
self.loop.set_exception_handler(None)
402405
logger = logging.getLogger('asyncio')
403406

404407
def run_loop():

tests/test_tcp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,10 @@ async def start_server():
10481048
client.stop()
10491049

10501050
def test_create_connection_ssl_1(self):
1051+
if self.implementation == 'asyncio':
1052+
# Don't crash on asyncio errors
1053+
self.loop.set_exception_handler(None)
1054+
10511055
CNT = 0
10521056
TOTAL_CNT = 25
10531057

uvloop/_testbase.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import gc
99
import logging
1010
import os
11+
import pprint
1112
import re
1213
import select
1314
import socket
@@ -71,11 +72,17 @@ def is_asyncio_loop(self):
7172
def run_loop_briefly(self, *, delay=0.01):
7273
self.loop.run_until_complete(asyncio.sleep(delay, loop=self.loop))
7374

75+
def loop_exception_handler(self, loop, context):
76+
self.__unhandled_exceptions.append(context)
77+
7478
def setUp(self):
7579
self.loop = self.new_loop()
7680
asyncio.set_event_loop(None)
7781
self._check_unclosed_resources_in_debug = True
7882

83+
self.loop.set_exception_handler(self.loop_exception_handler)
84+
self.__unhandled_exceptions = []
85+
7986
if hasattr(asyncio, '_get_running_loop'):
8087
# Disable `_get_running_loop`.
8188
self._get_running_loop = asyncio.events._get_running_loop
@@ -84,6 +91,12 @@ def setUp(self):
8491
def tearDown(self):
8592
self.loop.close()
8693

94+
if self.__unhandled_exceptions:
95+
print('Unexpected calls to loop.call_exception_handler():')
96+
pprint.pprint(self.__unhandled_exceptions)
97+
self.fail('unexpected calls to loop.call_exception_handler()')
98+
return
99+
87100
if hasattr(asyncio, '_get_running_loop'):
88101
asyncio.events._get_running_loop = self._get_running_loop
89102

0 commit comments

Comments
 (0)