'Calling L{Request.loseConnection} causes all data that has previously
been sent to be flushed, and then the stream cleanly closed.'

def test_loseH2StreamConnection(self):

    connection = H2Connection()
    connection.requestFactory = DummyProducerHandlerProxy
    (_, transport) = self.connectAndReceive(connection, self.getRequestHeaders, [])
    stream = connection.streams[1]
    request = stream._request.original
    dataChunks = ['hello', 'world', 'here', 'are', 'some', 'writes']
    for chunk in dataChunks:
        request.write(chunk)
    request.loseConnection()
    def validate(streamID):
        frames = framesFromBytes(transport.value())
        self.assertEqual(len(frames), 9)
        self.assertTrue(all(((f.stream_id == 1) for f in frames[1:])))
        self.assertTrue(isinstance(frames[1], hyperframe.frame.HeadersFrame))
        self.assertTrue(('END_STREAM' in frames[(-1)].flags))
        receivedDataChunks = [f.data for f in frames if isinstance(f, hyperframe.frame.DataFrame)]
        self.assertEqual(receivedDataChunks, (dataChunks + ['']))
    return connection._streamCleanupCallbacks[1].addCallback(validate)
