'Bytes written to L{TLSMemoryBIOProtocol} before the handshake is
complete are received by the protocol on the other side of the
connection once the handshake succeeds.'

def test_writeAfterHandshake(self):

    data = 'some    bytes'
    clientProtocol = Protocol()
    clientFactory = ClientFactory()
    clientFactory.protocol = (lambda : clientProtocol)
    (clientContextFactory, handshakeDeferred) = HandshakeCallbackContextFactory.factoryAndDeferred()
    wrapperFactory = TLSMemoryBIOFactory(clientContextFactory, True, clientFactory)
    sslClientProtocol = wrapperFactory.buildProtocol(None)
    serverProtocol = AccumulatingProtocol(len(data))
    serverFactory = ServerFactory()
    serverFactory.protocol = (lambda : serverProtocol)
    serverContextFactory = ServerTLSContext()
    wrapperFactory = TLSMemoryBIOFactory(serverContextFactory, False, serverFactory)
    sslServerProtocol = wrapperFactory.buildProtocol(None)
    connectionDeferred = loopbackAsync(sslServerProtocol, sslClientProtocol)
    def cbHandshook(ignored):
        clientProtocol.transport.write(data)
        return connectionDeferred
    handshakeDeferred.addCallback(cbHandshook)
    def cbDisconnected(ignored):
        self.assertEqual(''.join(serverProtocol.received), data)
    handshakeDeferred.addCallback(cbDisconnected)
    return handshakeDeferred
