'Calling L{Deferred.cancel} on the L{Deferred} returned from
L{IStreamClientEndpoint.connect} is errbacked with an expected
L{ConnectingCancelledError} exception.'

def test_endpointConnectingCancelled(self):

    mreactor = MemoryReactor()
    clientFactory = object()
    (ep, ignoredArgs, address) = self.createClientEndpoint(mreactor, clientFactory)
    d = ep.connect(clientFactory)
    receivedFailures = []
    def checkFailure(f):
        receivedFailures.append(f)
    d.addErrback(checkFailure)
    d.cancel()
    attemptFactory = self.retrieveConnectedFactory(mreactor)
    attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
    self.assertEqual(len(receivedFailures), 1)
    failure = receivedFailures[0]
    self.assertIsInstance(failure.value, error.ConnectingCancelledError)
    self.assertEqual(failure.value.address, address)
