cpython: 27fc857ea8af (original) (raw)
Mercurial > cpython
changeset 104111:27fc857ea8af
Issue #28283: Merge from 3.6 [#28283]
Berker Peksag berker.peksag@gmail.com | |
---|---|
date | Wed, 28 Sep 2016 00:40:42 +0300 |
parents | 675d3f76444d(current diff)b9f18dcbfc4b(diff) |
children | 8f0df4db2b06 |
files | |
diffstat | 1 files changed, 0 insertions(+), 86 deletions(-)[+] [-] Lib/test/test_asyncio/test_selector_events.py 86 |
line wrap: on
line diff
--- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -2,8 +2,6 @@ import errno import socket -import threading -import time import unittest from unittest import mock try: @@ -1786,89 +1784,5 @@ class SelectorDatagramTransportTests(tes 'Fatal error on transport\nprotocol:.\ntransport:.'), exc_info=(ConnectionRefusedError, MOCK_ANY, MOCK_ANY)) - -class SelectorLoopFunctionalTests(unittest.TestCase): -
- def setUp(self):
self.loop = asyncio.new_event_loop()[](#l1.20)
asyncio.set_event_loop(None)[](#l1.21)
- @asyncio.coroutine
- def recv_all(self, sock, nbytes):
buf = b''[](#l1.28)
while len(buf) < nbytes:[](#l1.29)
buf += yield from self.loop.sock_recv(sock, nbytes - len(buf))[](#l1.30)
return buf[](#l1.31)
- def test_sock_connect_sock_write_race(self):
TIMEOUT = 60.0[](#l1.34)
PAYLOAD = b'DATA' * 1024 * 1024[](#l1.35)
class Server(threading.Thread):[](#l1.37)
def __init__(self, *args, srv_sock, **kwargs):[](#l1.38)
super().__init__(*args, **kwargs)[](#l1.39)
self.srv_sock = srv_sock[](#l1.40)
def run(self):[](#l1.42)
with self.srv_sock:[](#l1.43)
srv_sock.listen(100)[](#l1.44)
sock, addr = self.srv_sock.accept()[](#l1.46)
sock.settimeout(TIMEOUT)[](#l1.47)
with sock:[](#l1.49)
sock.sendall(b'helo')[](#l1.50)
buf = bytearray()[](#l1.52)
while len(buf) < len(PAYLOAD):[](#l1.53)
pack = sock.recv(1024 * 65)[](#l1.54)
if not pack:[](#l1.55)
break[](#l1.56)
buf.extend(pack)[](#l1.57)
@asyncio.coroutine[](#l1.59)
def client(addr):[](#l1.60)
sock = socket.socket()[](#l1.61)
with sock:[](#l1.62)
sock.setblocking(False)[](#l1.63)
started = time.monotonic()[](#l1.65)
while True:[](#l1.66)
if time.monotonic() - started > TIMEOUT:[](#l1.67)
self.fail('unable to connect to the socket')[](#l1.68)
return[](#l1.69)
try:[](#l1.70)
yield from self.loop.sock_connect(sock, addr)[](#l1.71)
except OSError:[](#l1.72)
yield from asyncio.sleep(0.05, loop=self.loop)[](#l1.73)
else:[](#l1.74)
break[](#l1.75)
# Give 'Server' thread a chance to accept and send b'helo'[](#l1.77)
time.sleep(0.1)[](#l1.78)
data = yield from self.recv_all(sock, 4)[](#l1.80)
self.assertEqual(data, b'helo')[](#l1.81)
yield from self.loop.sock_sendall(sock, PAYLOAD)[](#l1.82)
srv_sock = socket.socket()[](#l1.84)
srv_sock.settimeout(TIMEOUT)[](#l1.85)
srv_sock.bind(('127.0.0.1', 0))[](#l1.86)
srv_addr = srv_sock.getsockname()[](#l1.87)
srv = Server(srv_sock=srv_sock, daemon=True)[](#l1.89)
srv.start()[](#l1.90)
try:[](#l1.92)
self.loop.run_until_complete([](#l1.93)
asyncio.wait_for(client(srv_addr), loop=self.loop,[](#l1.94)
timeout=TIMEOUT))[](#l1.95)
finally:[](#l1.96)
srv.join()[](#l1.97)