'An errback on the deferred returned by
L{client.Resolver.queryTCP} may trigger another TCP query.'

def test_reentrantTCPQueryErrbackOnConnectionFailure(self):

    reactor = proto_helpers.MemoryReactor()
    resolver = client.Resolver(servers=[('127.0.0.1', 10053)], reactor=reactor)
    q = dns.Query('example.com')
    d = resolver.queryTCP(q)
    def reissue(e):
        e.trap(ConnectionRefusedError)
        return resolver.queryTCP(q)
    d.addErrback(reissue)
    self.assertEqual(len(reactor.tcpClients), 1)
    self.assertEqual(len(reactor.connectors), 1)
    (host, port, factory, timeout, bindAddress) = reactor.tcpClients[0]
    f1 = failure.Failure(ConnectionRefusedError())
    factory.clientConnectionFailed(reactor.connectors[0], f1)
    self.assertEqual(len(reactor.tcpClients), 2)
    self.assertEqual(len(reactor.connectors), 2)
    self.assertNoResult(d)
    f2 = failure.Failure(ConnectionRefusedError())
    factory.clientConnectionFailed(reactor.connectors[1], f2)
    f = self.failureResultOf(d, ConnectionRefusedError)
    self.assertIs(f, f2)
