'Common code for tests involving writes by producer after
loseConnection is called.'

def loseConnectionWithProducer(self, writeBlockedOnRead):

    (clientProtocol, tlsProtocol, producer) = self.setupStreamingProducer()
    (serverProtocol, serverTLSProtocol) = buildTLSProtocol(server=True)
    if (not writeBlockedOnRead):
        self.flushTwoTLSProtocols(tlsProtocol, serverTLSProtocol)
    else:
        pass
    clientProtocol.transport.write('x    ')
    clientProtocol.transport.loseConnection()
    self.flushTwoTLSProtocols(tlsProtocol, serverTLSProtocol)
    self.assertFalse(tlsProtocol.transport.disconnecting)
    self.assertFalse(('stop' in producer.producerHistory))
    clientProtocol.transport.write('hello')
    clientProtocol.transport.writeSequence(['    ', 'world'])
    clientProtocol.transport.unregisterProducer()
    self.assertNotEqual(tlsProtocol.transport.value(), '')
    self.assertFalse(tlsProtocol.transport.disconnecting)
    clientProtocol.transport.write("won't")
    clientProtocol.transport.writeSequence(["won't!"])
    self.flushTwoTLSProtocols(tlsProtocol, serverTLSProtocol)
    self.assertTrue(tlsProtocol.transport.disconnecting)
    self.assertEqual(''.join(serverProtocol.received), 'x    hello    world')
