MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_reuse_reconnect

Method test_reuse_reconnect

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

Source from the content-addressed store, hash-verified

1932class PersistenceTest(TestCase):
1933
1934 def test_reuse_reconnect(self):
1935 # Should reuse or reconnect depending on header from server
1936 tests = (
1937 ('1.0', '', False),
1938 ('1.0', 'Connection: keep-alive\r\n', True),
1939 ('1.1', '', True),
1940 ('1.1', 'Connection: close\r\n', False),
1941 ('1.0', 'Connection: keep-ALIVE\r\n', True),
1942 ('1.1', 'Connection: cloSE\r\n', False),
1943 )
1944 for version, header, reuse in tests:
1945 with self.subTest(version=version, header=header):
1946 msg = (
1947 'HTTP/{} 200 OK\r\n'
1948 '{}'
1949 'Content-Length: 12\r\n'
1950 '\r\n'
1951 'Dummy body\r\n'
1952 ).format(version, header)
1953 conn = FakeSocketHTTPConnection(msg)
1954 self.assertIsNone(conn.sock)
1955 conn.request('GET', '/open-connection')
1956 with conn.getresponse() as response:
1957 self.assertEqual(conn.sock is None, not reuse)
1958 response.read()
1959 self.assertEqual(conn.sock is None, not reuse)
1960 self.assertEqual(conn.connections, 1)
1961 conn.request('GET', '/subsequent-request')
1962 self.assertEqual(conn.connections, 1 if reuse else 2)
1963
1964 def test_disconnected(self):
1965

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected