'L{loopback.loopbackAsync} does not call a protocol\'s C{dataReceived}
method while that protocol\'s transport\'s C{write} method is higher up
on the stack.'

def test_writeNotReentrant(self):

    class Server(Protocol, ):
        def dataReceived(self, bytes):
            self.transport.write('bytes')
    class Client(Protocol, ):
        ready = False
        def connectionMade(self):
            reactor.callLater(0, self.go)
        def go(self):
            self.transport.write('foo')
            self.ready = True
        def dataReceived(self, bytes):
            self.wasReady = self.ready
            self.transport.loseConnection()
    server = Server()
    client = Client()
    d = loopback.loopbackAsync(client, server)
    def cbFinished(ignored):
        self.assertTrue(client.wasReady)
    d.addCallback(cbFinished)
    return d
