31
31
load_tests = load_tests_apply_scenarios
34
def portable_socket_pair():
35
"""Return a pair of TCP sockets connected to each other.
37
Unlike socket.socketpair, this should work on Windows.
39
listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
40
listen_sock.bind(('127.0.0.1', 0))
42
client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
43
client_sock.connect(listen_sock.getsockname())
44
server_sock, addr = listen_sock.accept()
46
return server_sock, client_sock
34
49
class TCPClient(object):
36
51
def __init__(self):
255
270
h = server._make_handler(sock)
256
271
self.assertEqual(test_server._DEFAULT_TESTING_CLIENT_TIMEOUT,
257
272
h._client_timeout)
275
class FakeServer(object):
276
"""Minimal implementation to pass to TestingSmartConnectionHandler"""
277
backing_transport = None
278
root_client_path = '/'
281
class TestTestingSmartConnectionHandler(tests.TestCase):
283
def test_connection_timeout_suppressed(self):
284
self.overrideAttr(test_server, '_DEFAULT_TESTING_CLIENT_TIMEOUT', 0.01)
286
server_sock, client_sock = portable_socket_pair()
287
# This should timeout quickly, but not generate an exception.
288
handler = test_server.TestingSmartConnectionHandler(server_sock,
289
server_sock.getpeername(), s)
291
def test_connection_shutdown_while_serving_no_error(self):
293
server_sock, client_sock = portable_socket_pair()
294
class ShutdownConnectionHandler(
295
test_server.TestingSmartConnectionHandler):
297
def _build_protocol(self):
299
return super(ShutdownConnectionHandler, self)._build_protocol()
300
# This should trigger shutdown after the entering _build_protocol, and
301
# we should exit cleanly, without raising an exception.
302
handler = ShutdownConnectionHandler(server_sock,
303
server_sock.getpeername(), s)