#NEWLINE# def test_quiescentCallbackCalled( self ) : #NEWLINE# #INDENT# "\n        If after a response is done the {HTTP11ClientProtocol} stays open and\n        returns to QUIESCENT state, all per-request state is reset and the\n        C{quiescentCallback} is called with the protocol instance.\n\n        This is useful for implementing a persistent connection pool.\n\n        The C{quiescentCallback} is called *before* the response-receiving\n        protocol's C{connectionLost}, so that new requests triggered by end of\n        first request can re-use a persistent connection.\n        " #NEWLINE# quiescentResult = [ ] #NEWLINE# def callback( p ) : #NEWLINE# #INDENT# self . assertEqual ( p , protocol ) #NEWLINE# self . assertEqual ( p . state , 'QUIESCENT' ) #NEWLINE# quiescentResult . append ( p ) #NEWLINE# #UNINDENT# transport = StringTransport ( ) #NEWLINE# protocol = HTTP11ClientProtocol ( callback ) #NEWLINE# protocol . makeConnection ( transport ) #NEWLINE# requestDeferred = protocol . request ( Request ( b'GET' , b'/' , _boringHeaders , None , persistent = True ) ) #NEWLINE# protocol . dataReceived ( b'HTTP/1.1 200 OK\r\nContent-length: 3\r\n\r\n' ) #NEWLINE# self . assertEqual ( result , [ ] ) #NEWLINE# result = [ ] #NEWLINE# requestDeferred . addCallback ( result . append ) #NEWLINE# response = result [ 0 ] #NEWLINE# bodyProtocol = AccumulatingProtocol ( ) #NEWLINE# bodyProtocol . closedDeferred = Deferred ( ) #NEWLINE# bodyProtocol . closedDeferred . addCallback ( ( lambda ign : quiescentResult . append ( 'response done' ) ) ) #NEWLINE# response . deliverBody ( bodyProtocol ) #NEWLINE# protocol . dataReceived ( b'abc' ) #NEWLINE# bodyProtocol . closedReason . trap ( ResponseDone ) #NEWLINE# self . assertEqual ( quiescentResult , [ protocol , 'response done' ] ) #NEWLINE# self . assertEqual ( protocol . _parser , None ) #NEWLINE# self . assertEqual ( protocol . _finishedRequest , None ) #NEWLINE# self . assertEqual ( protocol . _currentRequest , None ) #NEWLINE# self . assertEqual ( protocol . _transportProxy , None ) #NEWLINE# self . assertEqual ( protocol . _responseDeferred , None )