'When L{HTTPConnectionPool.getConnection} connects, it returns a
C{Deferred} that fires with an instance of L{HTTP11ClientProtocol}
that has the correct quiescent callback attached. When this callback
is called the protocol is returned to the cache correctly, using the
right key.'

def test_getUsesQuiescentCallback(self):

    class StringEndpoint(object, ):
        def connect(self, factory):
            p = factory.buildProtocol(None)
            p.makeConnection(StringTransport())
            return succeed(p)
    pool = HTTPConnectionPool(self.fakeReactor, True)
    pool.retryAutomatically = False
    result = []
    key = 'a    key'
    pool.getConnection(key, StringEndpoint()).addCallback(result.append)
    protocol = result[0]
    self.assertIsInstance(protocol, HTTP11ClientProtocol)
    protocol._state = 'QUIESCENT'
    protocol._quiescentCallback(protocol)
    result2 = []
    pool.getConnection(key, StringEndpoint()).addCallback(result2.append)
    self.assertIdentical(result2[0], protocol)
