'If response bytes are delivered to L{HTTP11ClientProtocol} before the
request completes, calling C{connectionLost} on the protocol will
result in protocol being moved to C{\'CONNECTION_LOST\'} state.'

def test_connectionLostAfterReceivingResponseBeforeRequestGenerationDone(self):

    request = SlowRequest()
    d = self.protocol.request(request)
    self.protocol.dataReceived('HTTP/1.1    400    BAD    REQUEST\r\nContent-Length:    9\r\n\r\ntisk    tisk')
    def cbResponse(response):
        p = AccumulatingProtocol()
        whenFinished = p.closedDeferred = Deferred()
        response.deliverBody(p)
        return whenFinished.addCallback((lambda ign: (response, p.data)))
    d.addCallback(cbResponse)
    def cbAllResponse(ignore):
        request.finished.callback(None)
        self.protocol.connectionLost(Failure(ArbitraryException()))
        self.assertEqual(self.protocol._state, u'CONNECTION_LOST')
    d.addCallback(cbAllResponse)
    return d
