Skip to content

Commit fe61070

Browse files
committed
Add failing test
1 parent 5805a6f commit fe61070

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

tests/test_client_functional.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,93 @@ def go(url):
10201020
url = httpd.url('keepalive')
10211021
self.loop.run_until_complete(go(url))
10221022

1023+
def test_server_close_keepalive_connection(self):
1024+
1025+
class Proto(asyncio.Protocol):
1026+
1027+
def connection_made(self, transport):
1028+
self.transp = transport
1029+
self.data = b''
1030+
1031+
def data_received(self, data):
1032+
self.data += data
1033+
if data.endswith(b'\r\n\r\n'):
1034+
self.transp.write(
1035+
b'HTTP/1.1 200 OK\r\n'
1036+
b'CONTENT-LENGTH: 2\r\n'
1037+
b'CONNECTION: close\r\n'
1038+
b'\r\n'
1039+
b'ok')
1040+
self.transp.close()
1041+
1042+
def connection_lost(self, exc):
1043+
self.transp = None
1044+
1045+
@asyncio.coroutine
1046+
def go():
1047+
server = yield from self.loop.create_server(
1048+
Proto, '127.0.0.1')
1049+
1050+
addr = server.sockets[0].getsockname()
1051+
1052+
connector = aiohttp.TCPConnector(loop=self.loop)
1053+
1054+
url = 'http://{}:{}/'.format(*addr)
1055+
for i in range(2):
1056+
r = yield from client.request('GET', url,
1057+
connector=connector,
1058+
loop=self.loop)
1059+
yield from r.read()
1060+
self.assertEqual(0, len(connector._conns))
1061+
connector.close()
1062+
server.close()
1063+
yield from server.wait_closed()
1064+
1065+
self.loop.run_until_complete(go())
1066+
1067+
def test_handle_keepalive_on_closed_connection(self):
1068+
1069+
class Proto(asyncio.Protocol):
1070+
1071+
def connection_made(self, transport):
1072+
self.transp = transport
1073+
self.data = b''
1074+
1075+
def data_received(self, data):
1076+
self.data += data
1077+
if data.endswith(b'\r\n\r\n'):
1078+
self.transp.write(
1079+
b'HTTP/1.1 200 OK\r\n'
1080+
b'CONTENT-LENGTH: 2\r\n'
1081+
b'\r\n'
1082+
b'ok')
1083+
self.transp.close()
1084+
1085+
def connection_lost(self, exc):
1086+
self.transp = None
1087+
1088+
@asyncio.coroutine
1089+
def go():
1090+
server = yield from self.loop.create_server(
1091+
Proto, '127.0.0.1')
1092+
1093+
addr = server.sockets[0].getsockname()
1094+
1095+
connector = aiohttp.TCPConnector(loop=self.loop)
1096+
1097+
url = 'http://{}:{}/'.format(*addr)
1098+
for i in range(2):
1099+
r = yield from client.request('GET', url,
1100+
connector=connector,
1101+
loop=self.loop)
1102+
yield from r.read()
1103+
self.assertEqual(1, len(connector._conns))
1104+
connector.close()
1105+
server.close()
1106+
yield from server.wait_closed()
1107+
1108+
self.loop.run_until_complete(go())
1109+
10231110

10241111
class Functional(test_utils.Router):
10251112

0 commit comments

Comments
 (0)