'When the connection with the server is lost, the gzip protocol calls
C{flush} on the zlib decompressor object to get uncompressed data which
may have been buffered.'

def test_flushData(self):

    class decompressobj(object, ):
        def __init__(self, wbits):
            pass
        def decompress(self, data):
            return 'x'
        def flush(self):
            return 'y'
    oldDecompressObj = zlib.decompressobj
    zlib.decompressobj = decompressobj
    self.addCleanup(setattr, zlib, 'decompressobj', oldDecompressObj)
    deferred = self.agent.request('GET', 'http://example.com/foo')
    (req, res) = self.protocol.requests.pop()
    headers = http_headers.Headers({'content-encoding': ['gzip']})
    transport = StringTransport()
    response = Response(('HTTP', 1, 1), 200, 'OK', headers, transport)
    res.callback(response)
    def checkResponse(result):
        response._bodyDataReceived('data')
        response._bodyDataFinished()
        protocol = SimpleAgentProtocol()
        result.deliverBody(protocol)
        self.assertEqual(protocol.received, ['x', 'y'])
        return defer.gatherResults([protocol.made, protocol.finished])
    deferred.addCallback(checkResponse)
    return deferred
