Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit 3a8fc97

Browse files
committed
Drop test_sock_connect_sock_write_race (sync with CPython)
The test is highly unstable on some platforms, and it's hard to rewrite it to make it stable.
1 parent 15bfb5f commit 3a8fc97

File tree

1 file changed

+0
-86
lines changed

1 file changed

+0
-86
lines changed

tests/test_selector_events.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import errno
44
import socket
5-
import threading
6-
import time
75
import unittest
86
from unittest import mock
97
try:
@@ -1786,89 +1784,5 @@ def test_fatal_error_connected(self, m_exc):
17861784
'Fatal error on transport\nprotocol:.*\ntransport:.*'),
17871785
exc_info=(ConnectionRefusedError, MOCK_ANY, MOCK_ANY))
17881786

1789-
1790-
class SelectorLoopFunctionalTests(unittest.TestCase):
1791-
1792-
def setUp(self):
1793-
self.loop = asyncio.new_event_loop()
1794-
asyncio.set_event_loop(None)
1795-
1796-
def tearDown(self):
1797-
self.loop.close()
1798-
1799-
@asyncio.coroutine
1800-
def recv_all(self, sock, nbytes):
1801-
buf = b''
1802-
while len(buf) < nbytes:
1803-
buf += yield from self.loop.sock_recv(sock, nbytes - len(buf))
1804-
return buf
1805-
1806-
def test_sock_connect_sock_write_race(self):
1807-
TIMEOUT = 3.0
1808-
PAYLOAD = b'DATA' * 1024 * 1024
1809-
1810-
class Server(threading.Thread):
1811-
def __init__(self, *args, srv_sock, **kwargs):
1812-
super().__init__(*args, **kwargs)
1813-
self.srv_sock = srv_sock
1814-
1815-
def run(self):
1816-
with self.srv_sock:
1817-
srv_sock.listen(100)
1818-
1819-
sock, addr = self.srv_sock.accept()
1820-
sock.settimeout(TIMEOUT)
1821-
1822-
with sock:
1823-
sock.sendall(b'helo')
1824-
1825-
buf = bytearray()
1826-
while len(buf) < len(PAYLOAD):
1827-
pack = sock.recv(1024 * 65)
1828-
if not pack:
1829-
break
1830-
buf.extend(pack)
1831-
1832-
@asyncio.coroutine
1833-
def client(addr):
1834-
sock = socket.socket()
1835-
with sock:
1836-
sock.setblocking(False)
1837-
1838-
started = time.monotonic()
1839-
while True:
1840-
if time.monotonic() - started > TIMEOUT:
1841-
self.fail('unable to connect to the socket')
1842-
return
1843-
try:
1844-
yield from self.loop.sock_connect(sock, addr)
1845-
except OSError:
1846-
yield from asyncio.sleep(0.05, loop=self.loop)
1847-
else:
1848-
break
1849-
1850-
# Give 'Server' thread a chance to accept and send b'helo'
1851-
time.sleep(0.1)
1852-
1853-
data = yield from self.recv_all(sock, 4)
1854-
self.assertEqual(data, b'helo')
1855-
yield from self.loop.sock_sendall(sock, PAYLOAD)
1856-
1857-
srv_sock = socket.socket()
1858-
srv_sock.settimeout(TIMEOUT)
1859-
srv_sock.bind(('127.0.0.1', 0))
1860-
srv_addr = srv_sock.getsockname()
1861-
1862-
srv = Server(srv_sock=srv_sock, daemon=True)
1863-
srv.start()
1864-
1865-
try:
1866-
self.loop.run_until_complete(
1867-
asyncio.wait_for(client(srv_addr), loop=self.loop,
1868-
timeout=TIMEOUT))
1869-
finally:
1870-
srv.join()
1871-
1872-
18731787
if __name__ == '__main__':
18741788
unittest.main()

0 commit comments

Comments
 (0)