MCPcopy Index your code
hub / github.com/python/cpython / test_reuse_reconnect

Method test_reuse_reconnect

Lib/test/test_httplib.py:1980–2008  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1978class PersistenceTest(TestCase):
1979
1980 def test_reuse_reconnect(self):
1981 # Should reuse or reconnect depending on header from server
1982 tests = (
1983 ('1.0', '', False),
1984 ('1.0', 'Connection: keep-alive\r\n', True),
1985 ('1.1', '', True),
1986 ('1.1', 'Connection: close\r\n', False),
1987 ('1.0', 'Connection: keep-ALIVE\r\n', True),
1988 ('1.1', 'Connection: cloSE\r\n', False),
1989 )
1990 for version, header, reuse in tests:
1991 with self.subTest(version=version, header=header):
1992 msg = (
1993 'HTTP/{} 200 OK\r\n'
1994 '{}'
1995 'Content-Length: 12\r\n'
1996 '\r\n'
1997 'Dummy body\r\n'
1998 ).format(version, header)
1999 conn = FakeSocketHTTPConnection(msg)
2000 self.assertIsNone(conn.sock)
2001 conn.request('GET', '/open-connection')
2002 with conn.getresponse() as response:
2003 self.assertEqual(conn.sock is None, not reuse)
2004 response.read()
2005 self.assertEqual(conn.sock is None, not reuse)
2006 self.assertEqual(conn.connections, 1)
2007 conn.request('GET', '/subsequent-request')
2008 self.assertEqual(conn.connections, 1 if reuse else 2)
2009
2010 def test_disconnected(self):
2011

Callers

nothing calls this directly

Calls 8

assertIsNoneMethod · 0.80
subTestMethod · 0.45
formatMethod · 0.45
requestMethod · 0.45
getresponseMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected