|
2 | 2 |
|
3 | 3 | import concurrent.futures |
4 | 4 | import errno |
5 | | -import logging |
6 | 5 | import math |
7 | 6 | import os |
8 | 7 | import socket |
|
15 | 14 | import asyncio |
16 | 15 | from asyncio import base_events |
17 | 16 | from asyncio import constants |
18 | | -from asyncio import events |
19 | 17 | from test.test_asyncio import utils as test_utils |
20 | 18 | from test import support |
21 | 19 | from test.support.script_helper import assert_python_ok |
@@ -288,7 +286,7 @@ def cb(): |
288 | 286 | loop.set_debug(debug) |
289 | 287 | if debug: |
290 | 288 | msg = ("Non-thread-safe operation invoked on an event loop other " |
291 | | - "than the current one") |
| 289 | + "than the current one") |
292 | 290 | with self.assertRaisesRegex(RuntimeError, msg): |
293 | 291 | loop.call_soon(cb) |
294 | 292 | with self.assertRaisesRegex(RuntimeError, msg): |
@@ -2075,5 +2073,31 @@ def test_negative_offset(self): |
2075 | 2073 | self.run_loop(self.loop.sock_sendfile(sock, self.file, -1)) |
2076 | 2074 |
|
2077 | 2075 |
|
| 2076 | +class TestSelectorUtils(test_utils.TestCase): |
| 2077 | + def check_set_nodelay(self, sock): |
| 2078 | + opt = sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY) |
| 2079 | + self.assertFalse(opt) |
| 2080 | + |
| 2081 | + base_events._set_nodelay(sock) |
| 2082 | + |
| 2083 | + opt = sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY) |
| 2084 | + self.assertTrue(opt) |
| 2085 | + |
| 2086 | + @unittest.skipUnless(hasattr(socket, 'TCP_NODELAY'), |
| 2087 | + 'need socket.TCP_NODELAY') |
| 2088 | + def test_set_nodelay(self): |
| 2089 | + sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM, |
| 2090 | + proto=socket.IPPROTO_TCP) |
| 2091 | + with sock: |
| 2092 | + self.check_set_nodelay(sock) |
| 2093 | + |
| 2094 | + sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM, |
| 2095 | + proto=socket.IPPROTO_TCP) |
| 2096 | + with sock: |
| 2097 | + sock.setblocking(False) |
| 2098 | + self.check_set_nodelay(sock) |
| 2099 | + |
| 2100 | + |
| 2101 | + |
2078 | 2102 | if __name__ == '__main__': |
2079 | 2103 | unittest.main() |
0 commit comments