summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_unix_events.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2018-02-25 16:32:14 (GMT)
committerGitHub <noreply@github.com>2018-02-25 16:32:14 (GMT)
commita19fb3c6aaa7632410d1d9dcb395d7101d124da4 (patch)
tree476902dc75526cc8bb22c41cf213416384c36805 /Lib/test/test_asyncio/test_unix_events.py
parent5fb632e83136399bad9427ee23ec8b771695290a (diff)
downloadcpython-a19fb3c6aaa7632410d1d9dcb395d7101d124da4.zip
cpython-a19fb3c6aaa7632410d1d9dcb395d7101d124da4.tar.gz
cpython-a19fb3c6aaa7632410d1d9dcb395d7101d124da4.tar.bz2
bpo-32622: Native sendfile on windows (#5565)
* Support sendfile on Windows Proactor event loop naively.
Diffstat (limited to 'Lib/test/test_asyncio/test_unix_events.py')
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py64
1 files changed, 9 insertions, 55 deletions
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 5bd76d3..104f995 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -466,10 +466,13 @@ class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase):
self.addCleanup(self.file.close)
super().setUp()
- def make_socket(self, blocking=False):
+ def make_socket(self, cleanup=True):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.setblocking(blocking)
- self.addCleanup(sock.close)
+ sock.setblocking(False)
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024)
+ if cleanup:
+ self.addCleanup(sock.close)
return sock
def run_loop(self, coro):
@@ -479,8 +482,10 @@ class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase):
sock = self.make_socket()
proto = self.MyProto(self.loop)
port = support.find_unused_port()
+ srv_sock = self.make_socket(cleanup=False)
+ srv_sock.bind((support.HOST, port))
server = self.run_loop(self.loop.create_server(
- lambda: proto, support.HOST, port))
+ lambda: proto, sock=srv_sock))
self.run_loop(self.loop.sock_connect(sock, (support.HOST, port)))
def cleanup():
@@ -497,27 +502,6 @@ class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase):
return sock, proto
- def test_sock_sendfile_success(self):
- sock, proto = self.prepare()
- ret = self.run_loop(self.loop.sock_sendfile(sock, self.file))
- sock.close()
- self.run_loop(proto.wait_closed())
-
- self.assertEqual(ret, len(self.DATA))
- self.assertEqual(proto.data, self.DATA)
- self.assertEqual(self.file.tell(), len(self.DATA))
-
- def test_sock_sendfile_with_offset_and_count(self):
- sock, proto = self.prepare()
- ret = self.run_loop(self.loop.sock_sendfile(sock, self.file,
- 1000, 2000))
- sock.close()
- self.run_loop(proto.wait_closed())
-
- self.assertEqual(proto.data, self.DATA[1000:3000])
- self.assertEqual(self.file.tell(), 3000)
- self.assertEqual(ret, 2000)
-
def test_sock_sendfile_not_available(self):
sock, proto = self.prepare()
with mock.patch('asyncio.unix_events.os', spec=[]):
@@ -555,36 +539,6 @@ class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase):
0, None))
self.assertEqual(self.file.tell(), 0)
- def test_sock_sendfile_zero_size(self):
- sock, proto = self.prepare()
- fname = support.TESTFN + '.suffix'
- with open(fname, 'wb') as f:
- pass # make zero sized file
- f = open(fname, 'rb')
- self.addCleanup(f.close)
- self.addCleanup(support.unlink, fname)
- ret = self.run_loop(self.loop._sock_sendfile_native(sock, f,
- 0, None))
- sock.close()
- self.run_loop(proto.wait_closed())
-
- self.assertEqual(ret, 0)
- self.assertEqual(self.file.tell(), 0)
-
- def test_sock_sendfile_mix_with_regular_send(self):
- buf = b'1234567890' * 1024 * 1024 # 10 MB
- sock, proto = self.prepare()
- self.run_loop(self.loop.sock_sendall(sock, buf))
- ret = self.run_loop(self.loop.sock_sendfile(sock, self.file))
- self.run_loop(self.loop.sock_sendall(sock, buf))
- sock.close()
- self.run_loop(proto.wait_closed())
-
- self.assertEqual(ret, len(self.DATA))
- expected = buf + self.DATA + buf
- self.assertEqual(proto.data, expected)
- self.assertEqual(self.file.tell(), len(self.DATA))
-
def test_sock_sendfile_cancel1(self):
sock, proto = self.prepare()