'L{client.HTTPConnectionPool} creates
{client._RetryingHTTP11ClientProtocol} with a new connection factory
method that creates a new connection using the same key and endpoint
as the wrapped connection.'

def test_retryWithNewConnection(self):

    pool = client.HTTPConnectionPool(Clock())
    key = 123
    endpoint = DummyEndpoint()
    newConnections = []
    def newConnection(k, e):
        newConnections.append((k, e))
    pool._newConnection = newConnection
    protocol = StubHTTPProtocol()
    protocol.makeConnection(StringTransport())
    pool._putConnection(key, protocol)
    d = pool.getConnection(key, endpoint)
    def gotConnection(connection):
        self.assertIsInstance(connection, client._RetryingHTTP11ClientProtocol)
        self.assertIdentical(connection._clientProtocol, protocol)
        self.assertEqual(newConnections, [])
        connection._newConnection()
        self.assertEqual(len(newConnections), 1)
        self.assertEqual(newConnections[0][0], key)
        self.assertIdentical(newConnections[0][1], endpoint)
    return d.addCallback(gotConnection)
