'If an MX lookup returns two CNAME records which point to each other,
the loop should be detected and the L{Deferred} returned by
L{MXCalculator.getMX} should be errbacked with L{CanonicalNameLoop}.'

def test_cnameLoopWithGlueRecords(self):

    firstAlias = 'cname1.example.com'
    secondAlias = 'cname2.example.com'
    class DummyResolver(object, ):
        def lookupMailExchange(self, domain):
            return defer.succeed(([RRHeader(name=firstAlias, type=Record_CNAME.TYPE, payload=Record_CNAME(secondAlias)), RRHeader(name=secondAlias, type=Record_CNAME.TYPE, payload=Record_CNAME(firstAlias))], [], []))
    self.mx.resolver = DummyResolver()
    d = self.mx.getMX(firstAlias)
    self.assertFailure(d, twisted.mail.relaymanager.CanonicalNameLoop)
    return d
