'If after a response is done the {HTTP11ClientProtocol} stays open and
returns to QUIESCENT state, all per-request state is reset and the
C{quiescentCallback} is called with the protocol instance.
This is useful for implementing a persistent connection pool.
The C{quiescentCallback} is called *before* the response-receiving
protocol\'s C{connectionLost}, so that new requests triggered by end of
first request can re-use a persistent connection.'

def test_quiescentCallbackCalled(self):

    quiescentResult = []
    def callback(p):
        self.assertEqual(p, protocol)
        self.assertEqual(p.state, u'QUIESCENT')
        quiescentResult.append(p)
    transport = StringTransport()
    protocol = HTTP11ClientProtocol(callback)
    protocol.makeConnection(transport)
    requestDeferred = protocol.request(Request('GET', '/', _boringHeaders, None, persistent=True))
    protocol.dataReceived('HTTP/1.1    200    OK\r\nContent-length:    3\r\n\r\n')
    self.assertEqual(quiescentResult, [])
    result = []
    requestDeferred.addCallback(result.append)
    response = result[0]
    bodyProtocol = AccumulatingProtocol()
    bodyProtocol.closedDeferred = Deferred()
    bodyProtocol.closedDeferred.addCallback((lambda ign: quiescentResult.append(u'response    done')))
    response.deliverBody(bodyProtocol)
    protocol.dataReceived('abc')
    bodyProtocol.closedReason.trap(ResponseDone)
    self.assertEqual(quiescentResult, [protocol, u'response    done'])
    self.assertEqual(protocol._parser, None)
    self.assertEqual(protocol._finishedRequest, None)
    self.assertEqual(protocol._currentRequest, None)
    self.assertEqual(protocol._transportProxy, None)
    self.assertEqual(protocol._responseDeferred, None)
