'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 = protocol.Factory()
    clientFactory.protocol = protocol.Protocol
    (ep, ignoredArgs, address) = self.createClientEndpoint(deterministicResolvingReactor(mreactor, ['127.0.0.1']), clientFactory)
    d = ep.connect(clientFactory)
    d.cancel()
    attemptFactory = self.retrieveConnectedFactory(mreactor)
    attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
    failure = self.failureResultOf(d)
    self.assertIsInstance(failure.value, error.ConnectingCancelledError)
    self.assertEqual(failure.value.address, address)
    self.assertTrue(mreactor.tcpClients[0][2]._connector.stoppedConnecting)
    self.assertEqual([], mreactor.getDelayedCalls())
