'L{IUNIXTransport.sendFileDescriptor} sends file descriptors before
L{ITransport.write} sends normal bytes.'

def test_descriptorDeliveredBeforeBytes(self):

    @implementer(IFileDescriptorReceiver)
    class RecordEvents(ConnectableProtocol, ):
        def connectionMade(self):
            ConnectableProtocol.connectionMade(self)
            self.events = []
        def fileDescriptorReceived(innerSelf, descriptor):
            self.addCleanup(close, descriptor)
            innerSelf.events.append(type(descriptor))
        def dataReceived(self, data):
            self.events.extend(data)
    cargo = socket()
    server = SendFileDescriptor(cargo.fileno(), 'junk')
    client = RecordEvents()
    runProtocolsWithReactor(self, server, client, self.endpoints)
    self.assertEqual(int, client.events[0])
    if _PY3:
        self.assertEqual('junk', bytes(client.events[1:]))
    else:
        self.assertEqual('junk', ''.join(client.events[1:]))
