'L{client.Resolver.queryUDP} should issue queries to its
L{dns.DNSDatagramProtocol} with server addresses taken from its own
C{servers} and C{dynServers} lists, proceeding through them in order
as L{DNSQueryTimeoutError}s occur.'

def test_datagramQueryServerOrder(self):

    protocol = StubDNSDatagramProtocol()
    servers = [('::1', 53), ('::2', 53)]
    dynServers = [('::3', 53), ('::4', 53)]
    resolver = client.Resolver(servers=servers)
    resolver.dynServers = dynServers
    resolver._connectedProtocol = (lambda interface: protocol)
    expectedResult = object()
    queryResult = resolver.queryUDP(None)
    queryResult.addCallback(self.assertEqual, expectedResult)
    self.assertEqual(len(protocol.queries), 1)
    self.assertIs(protocol.queries[0][0], servers[0])
    protocol.queries[0][(-1)].errback(DNSQueryTimeoutError(0))
    self.assertEqual(len(protocol.queries), 2)
    self.assertIs(protocol.queries[1][0], servers[1])
    protocol.queries[1][(-1)].errback(DNSQueryTimeoutError(1))
    self.assertEqual(len(protocol.queries), 3)
    self.assertIs(protocol.queries[2][0], dynServers[0])
    protocol.queries[2][(-1)].errback(DNSQueryTimeoutError(2))
    self.assertEqual(len(protocol.queries), 4)
    self.assertIs(protocol.queries[3][0], dynServers[1])
    protocol.queries[3][(-1)].callback(expectedResult)
    return queryResult
