Skip to content

Commit cc10f73

Browse files
committed
tests: Another attempt to fix test_signals_restore on Travis
1 parent e720208 commit cc10f73

File tree

2 files changed

+47
-91
lines changed

2 files changed

+47
-91
lines changed

tests/test_signals.py

Lines changed: 30 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,36 @@
77

88
from uvloop import _testbase as tb
99

10-
DELAY = 0.01
10+
DELAY = 0.1
1111

1212

1313
class _TestSignal:
1414
NEW_LOOP = None
1515

16+
@tb.silence_long_exec_warning()
1617
def test_signals_sigint_pycode_stop(self):
1718
async def runner():
1819
PROG = R"""\
1920
import asyncio
2021
import uvloop
2122
import time
2223
24+
from uvloop import _testbase as tb
25+
2326
async def worker():
2427
print('READY', flush=True)
2528
time.sleep(200)
2629
27-
loop = """ + self.NEW_LOOP + """
28-
asyncio.set_event_loop(loop)
29-
loop.run_until_complete(worker())
30+
@tb.silence_long_exec_warning()
31+
def run():
32+
loop = """ + self.NEW_LOOP + """
33+
asyncio.set_event_loop(loop)
34+
try:
35+
loop.run_until_complete(worker())
36+
finally:
37+
loop.close()
38+
39+
run()
3040
"""
3141

3242
proc = await asyncio.create_subprocess_exec(
@@ -44,13 +54,16 @@ async def worker():
4454

4555
self.loop.run_until_complete(runner())
4656

57+
@tb.silence_long_exec_warning()
4758
def test_signals_sigint_pycode_continue(self):
4859
async def runner():
4960
PROG = R"""\
5061
import asyncio
5162
import uvloop
5263
import time
5364
65+
from uvloop import _testbase as tb
66+
5467
async def worker():
5568
print('READY', flush=True)
5669
try:
@@ -60,9 +73,16 @@ async def worker():
6073
await asyncio.sleep(0.5)
6174
print('done')
6275
63-
loop = """ + self.NEW_LOOP + """
64-
asyncio.set_event_loop(loop)
65-
loop.run_until_complete(worker())
76+
@tb.silence_long_exec_warning()
77+
def run():
78+
loop = """ + self.NEW_LOOP + """
79+
asyncio.set_event_loop(loop)
80+
try:
81+
loop.run_until_complete(worker())
82+
finally:
83+
loop.close()
84+
85+
run()
6686
"""
6787

6888
proc = await asyncio.create_subprocess_exec(
@@ -80,6 +100,7 @@ async def worker():
80100

81101
self.loop.run_until_complete(runner())
82102

103+
@tb.silence_long_exec_warning()
83104
def test_signals_sigint_uvcode(self):
84105
async def runner():
85106
PROG = R"""\
@@ -119,6 +140,7 @@ async def worker():
119140

120141
self.loop.run_until_complete(runner())
121142

143+
@tb.silence_long_exec_warning()
122144
def test_signals_sigint_and_custom_handler(self):
123145
async def runner():
124146
PROG = R"""\
@@ -172,6 +194,7 @@ def handler_hup(say):
172194

173195
self.loop.run_until_complete(runner())
174196

197+
@tb.silence_long_exec_warning()
175198
def test_signals_and_custom_handler_1(self):
176199
async def runner():
177200
PROG = R"""\
@@ -243,90 +266,6 @@ def handler_hup():
243266
class Test_UV_Signals(_TestSignal, tb.UVTestCase):
244267
NEW_LOOP = 'uvloop.new_event_loop()'
245268

246-
def test_signals_restore(self):
247-
# Test that uvloop restores signals installed with the signals
248-
# module after the loop is done running.
249-
250-
async def runner():
251-
PROG = R"""\
252-
import asyncio
253-
import uvloop
254-
import signal
255-
import time
256-
257-
srv = None
258-
259-
async def worker():
260-
global srv
261-
cb = lambda *args: None
262-
srv = await asyncio.start_server(cb, '127.0.0.1', 0)
263-
print('READY', flush=True)
264-
265-
def py_handler(signum, frame):
266-
print('pyhandler', flush=True)
267-
268-
def aio_handler():
269-
print('aiohandler', flush=True)
270-
loop.stop()
271-
272-
signal.signal(signal.SIGUSR1, py_handler)
273-
274-
print('step1', flush=True)
275-
print(input(), flush=True)
276-
loop = """ + self.NEW_LOOP + """
277-
loop.add_signal_handler(signal.SIGUSR1, aio_handler)
278-
asyncio.set_event_loop(loop)
279-
loop.create_task(worker())
280-
try:
281-
loop.run_forever()
282-
finally:
283-
srv.close()
284-
loop.run_until_complete(srv.wait_closed())
285-
loop.close()
286-
print('step3', flush=True)
287-
print(input(), flush=True)
288-
"""
289-
290-
proc = await asyncio.create_subprocess_exec(
291-
sys.executable, b'-c', PROG,
292-
stdin=subprocess.PIPE,
293-
stdout=subprocess.PIPE,
294-
stderr=subprocess.PIPE,
295-
loop=self.loop)
296-
297-
ln = await proc.stdout.readline()
298-
self.assertEqual(ln, b'step1\n')
299-
300-
proc.send_signal(signal.SIGUSR1)
301-
ln = await proc.stdout.readline()
302-
self.assertEqual(ln, b'pyhandler\n')
303-
304-
proc.stdin.write(b'test\n')
305-
ln = await proc.stdout.readline()
306-
self.assertEqual(ln, b'test\n')
307-
308-
ln = await proc.stdout.readline()
309-
self.assertEqual(ln, b'READY\n')
310-
311-
proc.send_signal(signal.SIGUSR1)
312-
ln = await proc.stdout.readline()
313-
self.assertEqual(ln, b'aiohandler\n')
314-
315-
ln = await proc.stdout.readline()
316-
self.assertEqual(ln, b'step3\n')
317-
318-
proc.send_signal(signal.SIGUSR1)
319-
ln = await proc.stdout.readline()
320-
self.assertEqual(ln, b'pyhandler\n')
321-
322-
proc.stdin.write(b'done\n')
323-
324-
out, err = await proc.communicate()
325-
self.assertEqual(out, b'done\n')
326-
self.assertEqual(err, b'')
327-
328-
self.loop.run_until_complete(runner())
329-
330269

331270
class Test_AIO_Signals(_TestSignal, tb.AIOTestCase):
332271
NEW_LOOP = 'asyncio.new_event_loop()'

uvloop/_testbase.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ def _cert_fullname(name):
6868
return fullname
6969

7070

71+
@contextlib.contextmanager
72+
def silence_long_exec_warning():
73+
74+
class Filter(logging.Filter):
75+
def filter(self, record):
76+
return not (record.msg.startswith('Executing') and
77+
record.msg.endswith('seconds'))
78+
79+
logger = logging.getLogger('asyncio')
80+
filter = Filter()
81+
logger.addFilter(filter)
82+
try:
83+
yield
84+
finally:
85+
logger.removeFilter(filter)
86+
87+
7188
class SSLTestCase:
7289

7390
ONLYCERT = _cert_fullname('ssl_cert.pem')

0 commit comments

Comments
 (0)