'If associated with a protocol which does not provide
L{IFileDescriptorReceiver}, file descriptors received by the
L{IUNIXTransport} implementation are closed and a warning is emitted.'

def test_avoidLeakingFileDescriptors(self):

    from socket import socketpair
    (probeClient, probeServer) = socketpair()
    events = []
    addObserver(events.append)
    self.addCleanup(removeObserver, events.append)
    class RecordEndpointAddresses(SendFileDescriptor, ):
        def connectionMade(self):
            self.hostAddress = self.transport.getHost()
            self.peerAddress = self.transport.getPeer()
            SendFileDescriptor.connectionMade(self)
    server = RecordEndpointAddresses(probeClient.fileno(), 'junk')
    client = ConnectableProtocol()
    runProtocolsWithReactor(self, server, client, self.endpoints)
    probeClient.close()
    probeServer.setblocking(False)
    self.assertEqual('', probeServer.recv(1024))
    format = '%(protocolName)s    (on    %(hostAddress)r)    does    not    provide    IFileDescriptorReceiver;    closing    file    descriptor    received    (from    %(peerAddress)r).'
    clsName = 'ConnectableProtocol'
    expectedEvent = dict(hostAddress=server.peerAddress, peerAddress=server.hostAddress, protocolName=clsName, format=format)
    for logEvent in events:
        for (k, v) in iteritems(expectedEvent):
            if (v != logEvent.get(k)):
                break
        else:
            break
    else:
        self.fail(('Expected    event    (%s)    not    found    in    logged    events    (%s)' % (expectedEvent, pformat(events))))
