]> granicus.if.org Git - python/commitdiff
[3.7] bpo-33353: Fix test_asyncio on FreeBSD (GH-7087)
authorVictor Stinner <vstinner@redhat.com>
Thu, 24 May 2018 01:21:14 +0000 (03:21 +0200)
committerGitHub <noreply@github.com>
Thu, 24 May 2018 01:21:14 +0000 (03:21 +0200)
* bpo-33353: test_asyncio uses smaller sendfile data (#7083)

bpo-32622, bpo-33353: sendfile() tests of test_asyncio use socket
buffers of 1 kB "to test on relative small data sets". Send only
160 KiB rather 10 MB to make the test much faster.

Shrink also SendfileBase.DATA from 1600 KiB to 160 KiB.

On Linux, 3 test_sock_sendfile_mix_with_regular_send() runs now take
less than 1 second, instead of 18 seconds.

On FreeBSD, the 3 tests didn't hang, but took 3 minutes. Now
the 3 tests pass in less than 1 seconds.

(cherry picked from commit 2932755cc11fd82b4908d60b24b837aa4f3028e6)

* bpo-33353: test_asyncio set SO_SNDBUF after connect (GH-7086)

bpo-32622, bpo-33353: On macOS, sock.connect() changes the
SO_SNDBUF value. Only set SO_SNDBUF and SO_RCVBUF buffer sizes
once a socket is connected or binded, not before.

(cherry picked from commit b97de3dd86046ac46567146d86a69d4f78ea09db)

Lib/test/test_asyncio/test_events.py

index 66c77b976dce1db537a84793e82d37eefb65458c..64d726d16d1cd89f6dae9ab89d7c1ee82b57026d 100644 (file)
@@ -2095,7 +2095,7 @@ class SubprocessTestsMixin:
 
 class SendfileBase:
 
-    DATA = b"12345abcde" * 160 * 1024  # 160 KiB
+    DATA = b"12345abcde" * 16 * 1024  # 160 KiB
 
     @classmethod
     def setUpClass(cls):
@@ -2142,11 +2142,15 @@ class SockSendfileMixin(SendfileBase):
         async def wait_closed(self):
             await self.fut
 
+    def set_socket_opts(self, sock):
+        # On macOS, SO_SNDBUF is reset by connect(). So this method
+        # should be called after the socket is connected.
+        sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
+        sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024)
+
     def make_socket(self, cleanup=True):
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         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
@@ -2159,7 +2163,9 @@ class SockSendfileMixin(SendfileBase):
         srv_sock.bind((support.HOST, port))
         server = self.run_loop(self.loop.create_server(
             lambda: proto, sock=srv_sock))
+        self.set_socket_opts(srv_sock)
         self.run_loop(self.loop.sock_connect(sock, ('127.0.0.1', port)))
+        self.set_socket_opts(sock)
 
         def cleanup():
             if proto.transport is not None:
@@ -2208,7 +2214,7 @@ class SockSendfileMixin(SendfileBase):
         self.assertEqual(self.file.tell(), 0)
 
     def test_sock_sendfile_mix_with_regular_send(self):
-        buf = b'1234567890' * 1024 * 1024  # 10 MB
+        buf = b"X" * 160 * 1024  # 160 KiB
         sock, proto = self.prepare_socksendfile()
         self.run_loop(self.loop.sock_sendall(sock, buf))
         ret = self.run_loop(self.loop.sock_sendfile(sock, self.file))
@@ -2264,9 +2270,9 @@ class SendfileMixin(SendfileBase):
         else:
             server_hostname = None
         cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        cli_sock.connect((support.HOST, port))
         # reduce send socket buffer size to test on relative small data sets
         cli_sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
-        cli_sock.connect((support.HOST, port))
         cli_proto = self.MySendfileProto(loop=self.loop)
         tr, pr = self.run_loop(self.loop.create_connection(
             lambda: cli_proto, sock=cli_sock,