7
7
8
8
from uvloop import _testbase as tb
9
9
10
- DELAY = 0.01
10
+ DELAY = 0.1
11
11
12
12
13
13
class _TestSignal :
14
14
NEW_LOOP = None
15
15
16
+ @tb .silence_long_exec_warning ()
16
17
def test_signals_sigint_pycode_stop (self ):
17
18
async def runner ():
18
19
PROG = R"""\
19
20
import asyncio
20
21
import uvloop
21
22
import time
22
23
24
+ from uvloop import _testbase as tb
25
+
23
26
async def worker():
24
27
print('READY', flush=True)
25
28
time.sleep(200)
26
29
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()
30
40
"""
31
41
32
42
proc = await asyncio .create_subprocess_exec (
@@ -44,13 +54,16 @@ async def worker():
44
54
45
55
self .loop .run_until_complete (runner ())
46
56
57
+ @tb .silence_long_exec_warning ()
47
58
def test_signals_sigint_pycode_continue (self ):
48
59
async def runner ():
49
60
PROG = R"""\
50
61
import asyncio
51
62
import uvloop
52
63
import time
53
64
65
+ from uvloop import _testbase as tb
66
+
54
67
async def worker():
55
68
print('READY', flush=True)
56
69
try:
@@ -60,9 +73,16 @@ async def worker():
60
73
await asyncio.sleep(0.5)
61
74
print('done')
62
75
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()
66
86
"""
67
87
68
88
proc = await asyncio .create_subprocess_exec (
@@ -80,6 +100,7 @@ async def worker():
80
100
81
101
self .loop .run_until_complete (runner ())
82
102
103
+ @tb .silence_long_exec_warning ()
83
104
def test_signals_sigint_uvcode (self ):
84
105
async def runner ():
85
106
PROG = R"""\
@@ -119,6 +140,7 @@ async def worker():
119
140
120
141
self .loop .run_until_complete (runner ())
121
142
143
+ @tb .silence_long_exec_warning ()
122
144
def test_signals_sigint_and_custom_handler (self ):
123
145
async def runner ():
124
146
PROG = R"""\
@@ -172,6 +194,7 @@ def handler_hup(say):
172
194
173
195
self .loop .run_until_complete (runner ())
174
196
197
+ @tb .silence_long_exec_warning ()
175
198
def test_signals_and_custom_handler_1 (self ):
176
199
async def runner ():
177
200
PROG = R"""\
@@ -243,90 +266,6 @@ def handler_hup():
243
266
class Test_UV_Signals (_TestSignal , tb .UVTestCase ):
244
267
NEW_LOOP = 'uvloop.new_event_loop()'
245
268
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
-
330
269
331
270
class Test_AIO_Signals (_TestSignal , tb .AIOTestCase ):
332
271
NEW_LOOP = 'asyncio.new_event_loop()'
0 commit comments