'Assert that the error number of the ConnectionRefusedError is
ECONNREFUSED, and not some other socket related error.'

def test_connectionRefusedErrorNumber(self):

    serverSockets = []
    for i in range(10):
        serverSocket = socket.socket()
        serverSocket.bind(('127.0.0.1', 0))
        serverSocket.listen(1)
        serverSockets.append(serverSocket)
    random.shuffle(serverSockets)
    clientCreator = protocol.ClientCreator(reactor, protocol.Protocol)
    def tryConnectFailure():
        def connected(proto):
            '\n                                                                Darn.        Kill    it    and    try    again,    if    there    are    any    tries    left.\n                                                                '
            proto.transport.loseConnection()
            if serverSockets:
                return tryConnectFailure()
            self.fail('Could    not    fail    to    connect    -    could    not    test    errno    for    that    case.')
        serverSocket = serverSockets.pop()
        (serverHost, serverPort) = serverSocket.getsockname()
        serverSocket.close()
        connectDeferred = clientCreator.connectTCP(serverHost, serverPort)
        connectDeferred.addCallback(connected)
        return connectDeferred
    refusedDeferred = tryConnectFailure()
    self.assertFailure(refusedDeferred, error.ConnectionRefusedError)
    def connRefused(exc):
        self.assertEqual(exc.osError, errno.ECONNREFUSED)
    refusedDeferred.addCallback(connRefused)
    def cleanup(passthrough):
        while serverSockets:
            serverSockets.pop().close()
        return passthrough
    refusedDeferred.addBoth(cleanup)
    return refusedDeferred
