|
1 | 1 | """Tests for aiohttp/server.py"""
|
2 | 2 |
|
3 | 3 | import asyncio
|
| 4 | +import socket |
4 | 5 | import unittest
|
5 | 6 | import unittest.mock
|
6 | 7 |
|
@@ -65,6 +66,32 @@ def test_connection_made(self):
|
65 | 66 |
|
66 | 67 | srv.connection_made(unittest.mock.Mock())
|
67 | 68 | self.assertIsNotNone(srv._request_handler)
|
| 69 | + self.assertIsNotNone(srv._timeout_handle) |
| 70 | + |
| 71 | + def test_connection_made_without_timeout(self): |
| 72 | + srv = server.ServerHttpProtocol(loop=self.loop, timeout=0) |
| 73 | + |
| 74 | + srv.connection_made(unittest.mock.Mock()) |
| 75 | + self.assertIsNone(srv._timeout_handle) |
| 76 | + |
| 77 | + def test_connection_made_with_keepaplive(self): |
| 78 | + srv = server.ServerHttpProtocol(loop=self.loop) |
| 79 | + |
| 80 | + sock = unittest.mock.Mock() |
| 81 | + transport = unittest.mock.Mock() |
| 82 | + transport.get_extra_info.return_value = sock |
| 83 | + srv.connection_made(transport) |
| 84 | + sock.setsockopt.assert_called_with(socket.SOL_SOCKET, |
| 85 | + socket.SO_KEEPALIVE, 1) |
| 86 | + |
| 87 | + def test_connection_made_without_keepaplive(self): |
| 88 | + srv = server.ServerHttpProtocol(loop=self.loop, tcp_keepalive=False) |
| 89 | + |
| 90 | + sock = unittest.mock.Mock() |
| 91 | + transport = unittest.mock.Mock() |
| 92 | + transport.get_extra_info.return_value = sock |
| 93 | + srv.connection_made(transport) |
| 94 | + self.assertFalse(sock.setsockopt.called) |
68 | 95 |
|
69 | 96 | def test_data_received(self):
|
70 | 97 | srv = server.ServerHttpProtocol(loop=self.loop)
|
|
0 commit comments