Skip to content

Commit 5f48dab

Browse files
committed
tests: Support 3.8
1 parent 51636f7 commit 5f48dab

File tree

9 files changed

+114
-418
lines changed

9 files changed

+114
-418
lines changed

tests/test_base.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,16 @@ def test_run_until_complete_loop_orphan_future_close_loop(self):
347347
if self.implementation == 'asyncio' and sys.version_info < (3, 6, 2):
348348
raise unittest.SkipTest('unfixed asyncio')
349349

350-
class ShowStopper(BaseException):
351-
pass
352-
353350
async def foo(delay):
354351
await asyncio.sleep(delay)
355352

356353
def throw():
357-
raise ShowStopper
354+
raise KeyboardInterrupt
358355

359356
self.loop.call_soon(throw)
360357
try:
361358
self.loop.run_until_complete(foo(0.1))
362-
except ShowStopper:
359+
except KeyboardInterrupt:
363360
pass
364361

365362
# This call fails if run_until_complete does not clean up

tests/test_executors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
22
import concurrent.futures
3+
import multiprocessing
4+
import unittest
35

46
from uvloop import _testbase as tb
57

@@ -26,6 +28,9 @@ async def run():
2628
fib10 = [fib(i) for i in range(10)]
2729
self.loop.run_until_complete(run())
2830

31+
@unittest.skipIf(
32+
multiprocessing.get_start_method(False) == 'spawn',
33+
'no need to test on macOS where spawn is used instead of fork')
2934
def test_executors_process_pool_01(self):
3035
self.run_pool_test(concurrent.futures.ProcessPoolExecutor)
3136

tests/test_regr1.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import multiprocessing
44
import signal
55
import threading
6+
import unittest
7+
8+
import uvloop
69

710
from uvloop import _testbase as tb
811

@@ -32,35 +35,40 @@ class FailedTestError(BaseException):
3235
pass
3336

3437

38+
def run_server(quin, qout):
39+
server_loop = None
40+
41+
def server_thread():
42+
nonlocal server_loop
43+
loop = server_loop = uvloop.new_event_loop()
44+
asyncio.set_event_loop(loop)
45+
coro = loop.create_server(EchoServerProtocol, '127.0.0.1', 0)
46+
server = loop.run_until_complete(coro)
47+
addr = server.sockets[0].getsockname()
48+
qout.put(addr)
49+
loop.run_forever()
50+
server.close()
51+
loop.run_until_complete(server.wait_closed())
52+
try:
53+
loop.close()
54+
except Exception as exc:
55+
print(exc)
56+
qout.put('stopped')
57+
58+
thread = threading.Thread(target=server_thread, daemon=True)
59+
thread.start()
60+
61+
quin.get()
62+
server_loop.call_soon_threadsafe(server_loop.stop)
63+
thread.join(1)
64+
65+
3566
class TestIssue39Regr(tb.UVTestCase):
3667
"""See https://github.com/MagicStack/uvloop/issues/39 for details.
3768
3869
Original code to reproduce the bug is by Jim Fulton.
3970
"""
4071

41-
def run_server(self, quin, qout):
42-
def server_thread():
43-
loop = self.server_loop = self.new_loop()
44-
coro = loop.create_server(EchoServerProtocol, '127.0.0.1', 0)
45-
server = loop.run_until_complete(coro)
46-
addr = server.sockets[0].getsockname()
47-
qout.put(addr)
48-
loop.run_forever()
49-
server.close()
50-
loop.run_until_complete(server.wait_closed())
51-
try:
52-
loop.close()
53-
except Exception as exc:
54-
print(exc)
55-
qout.put('stopped')
56-
57-
thread = threading.Thread(target=server_thread, daemon=True)
58-
thread.start()
59-
60-
quin.get()
61-
self.server_loop.call_soon_threadsafe(self.server_loop.stop)
62-
thread.join(1)
63-
6472
def on_alarm(self, sig, fr):
6573
if self.running:
6674
raise FailedTestError
@@ -72,19 +80,20 @@ def run_test(self):
7280
if threaded:
7381
qin, qout = queue.Queue(), queue.Queue()
7482
threading.Thread(
75-
target=self.run_server,
83+
target=run_server,
7684
args=(qin, qout),
7785
daemon=True).start()
7886
else:
7987
qin = multiprocessing.Queue()
8088
qout = multiprocessing.Queue()
8189
multiprocessing.Process(
82-
target=self.run_server,
90+
target=run_server,
8391
args=(qin, qout),
8492
daemon=True).start()
8593

8694
addr = qout.get()
8795
loop = self.new_loop()
96+
asyncio.set_event_loop(loop)
8897
loop.create_task(
8998
loop.create_connection(
9099
lambda: EchoClientProtocol(loop),
@@ -96,6 +105,9 @@ def run_test(self):
96105
finally:
97106
loop.close()
98107

108+
@unittest.skipIf(
109+
multiprocessing.get_start_method(False) == 'spawn',
110+
'no need to test on macOS where spawn is used instead of fork')
99111
def test_issue39_regression(self):
100112
signal.signal(signal.SIGALRM, self.on_alarm)
101113
signal.alarm(5)

tests/test_signals.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
import sys
55
import time
6+
import unittest
67
import uvloop
78

89
from uvloop import _testbase as tb
@@ -280,6 +281,9 @@ def test_signals_no_SIGCHLD(self):
280281

281282
self.loop.add_signal_handler(signal.SIGCHLD, lambda *a: None)
282283

284+
@unittest.skipIf(sys.version_info[:3] >= (3, 8, 0),
285+
'in 3.8 a ThreadedChildWatcher is used '
286+
'(does not rely on SIGCHLD)')
283287
def test_asyncio_add_watcher_SIGCHLD_nop(self):
284288
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
285289
asyncio.get_event_loop_policy().get_child_watcher()

tests/test_sockets.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def test_socket_connect_recv_send(self):
2525
# See https://github.com/python/asyncio/pull/366 for details.
2626
raise unittest.SkipTest()
2727

28+
if sys.version_info[:3] >= (3, 8, 0):
29+
# @asyncio.coroutine is deprecated in 3.8
30+
raise unittest.SkipTest()
31+
2832
def srv_gen(sock):
2933
sock.send(b'helo')
3034
data = sock.recv_all(4 * _SIZE)
@@ -190,6 +194,11 @@ def test_socket_sync_remove_and_immediately_close(self):
190194
self.loop.run_until_complete(asyncio.sleep(0.01))
191195

192196
def test_sock_cancel_add_reader_race(self):
197+
if self.is_asyncio_loop() and sys.version_info[:3] == (3, 8, 0):
198+
# asyncio 3.8.0 seems to have a regression;
199+
# tracked in https://bugs.python.org/issue30064
200+
raise unittest.SkipTest()
201+
193202
srv_sock_conn = None
194203

195204
async def server():
@@ -236,6 +245,11 @@ async def send_server_data():
236245
self.loop.run_until_complete(server())
237246

238247
def test_sock_send_before_cancel(self):
248+
if self.is_asyncio_loop() and sys.version_info[:3] == (3, 8, 0):
249+
# asyncio 3.8.0 seems to have a regression;
250+
# tracked in https://bugs.python.org/issue30064
251+
raise unittest.SkipTest()
252+
239253
srv_sock_conn = None
240254

241255
async def server():

0 commit comments

Comments
 (0)