Exemplo n.º 1
0
        public void DnsResolver_Multiple_Lookup()
        {
            // This test issues simultanious A queries for the 13
            // global name servers and then verifies that the DnsResolver
            // was able to correctly correlate the responses to the
            // requests.

            IPAddress dns = GetDns();

            string[] gtld = new string[] {
                "a.gtld-servers.net.",
                "b.gtld-servers.net.",
                "c.gtld-servers.net.",
                "d.gtld-servers.net.",
                "e.gtld-servers.net.",
                "f.gtld-servers.net.",
                "g.gtld-servers.net.",
                "h.gtld-servers.net.",
                "i.gtld-servers.net.",
                "j.gtld-servers.net.",
                "k.gtld-servers.net.",
                "l.gtld-servers.net.",
                "m.gtld-servers.net.",
            };

            DnsRequest[]   requests  = new DnsRequest[gtld.Length];
            DnsResponse[]  responses = new DnsResponse[gtld.Length];
            IAsyncResult[] rgAR      = new IAsyncResult[gtld.Length];

            for (int j = 0; j < 10; j++)
            {
                // Repeat the test 10 times just for fun

                for (int i = 0; i < gtld.Length; i++)
                {
                    requests[i] = new DnsRequest(DnsFlag.RD, gtld[i], DnsQType.A);
                }

                for (int i = 0; i < gtld.Length; i++)
                {
                    rgAR[i] = DnsResolver.BeginQuery(dns, requests[i], timeout, null, null);
                }

                for (int i = 0; i < gtld.Length; i++)
                {
                    responses[i] = DnsResolver.EndQuery(rgAR[i]);
                }

                for (int i = 0; i < gtld.Length; i++)
                {
                    Assert.AreEqual(requests[i].QID, responses[i].QID);
                    Assert.AreEqual(requests[i].QName, responses[i].QName);
                }
            }
        }
Exemplo n.º 2
0
        public void DnsResolver_CancelAll()
        {
            IPAddress    dns = IPAddress.Loopback;
            DnsRequest   request;
            DnsResponse  response;
            IAsyncResult ar;

            // This test sends a DNS request to the loopback address
            // assuming that there is no DNS server running locally
            // and then calls DnsResolver.CancelAll() which should
            // terminate the query with a CancelException.

            request = new DnsRequest(DnsFlag.RD, "www.lilltek.com.", DnsQType.A);
            ar      = DnsResolver.BeginQuery(dns, request, timeout, null, null);

            DnsResolver.CancelAll();
            try
            {
                response = DnsResolver.EndQuery(ar);
                Assert.Fail("Expected a CancelException");
            }
            catch (CancelException)
            {
            }
            catch
            {
                Assert.Fail("Expected a CancelException");
            }
            finally
            {
                Thread.Sleep(1000);     // $todo(jeff.lill):

                // This test causes some problems for some other
                //tests unless I add this (I'm not sure why).
            }
        }
Exemplo n.º 3
0
        public void DnsResolver_Multiple_Lookup_Bind()
        {
            // This test repeats the A_Multiple test, but this time
            // after binding the DnsResolver to 5 client side sockets.

            IPAddress dns = GetDns();

            string[] gtld = new string[] {
                "a.gtld-servers.net.",
                "b.gtld-servers.net.",
                "c.gtld-servers.net.",
                "d.gtld-servers.net.",
                "e.gtld-servers.net.",
                "f.gtld-servers.net.",
                "g.gtld-servers.net.",
                "h.gtld-servers.net.",
                "i.gtld-servers.net.",
                "j.gtld-servers.net.",
                "k.gtld-servers.net.",
                "l.gtld-servers.net.",
                "m.gtld-servers.net.",
            };

            DnsRequest[]   requests  = new DnsRequest[gtld.Length];
            DnsResponse[]  responses = new DnsResponse[gtld.Length];
            IAsyncResult[] rgAR      = new IAsyncResult[gtld.Length];
            IPEndPoint[]   clientEPs;

            clientEPs = new IPEndPoint[10];
            for (int i = 0; i < clientEPs.Length; i++)
            {
                clientEPs[i] = new IPEndPoint(IPAddress.Any, 0);
            }

            DnsResolver.Bind(clientEPs, 128 * 1024, 128 * 1024);

            try
            {
                for (int j = 0; j < 10; j++)
                {
                    // Repeat the test 10 times just for fun

                    for (int i = 0; i < gtld.Length; i++)
                    {
                        requests[i] = new DnsRequest(DnsFlag.RD, gtld[i], DnsQType.A);
                    }

                    for (int i = 0; i < gtld.Length; i++)
                    {
                        rgAR[i] = DnsResolver.BeginQuery(dns, requests[i], timeout, null, null);
                    }

                    for (int i = 0; i < gtld.Length; i++)
                    {
                        responses[i] = DnsResolver.EndQuery(rgAR[i]);
                    }

                    for (int i = 0; i < gtld.Length; i++)
                    {
                        Assert.AreEqual(requests[i].QID, responses[i].QID);
                        Assert.AreEqual(requests[i].QName, responses[i].QName);
                    }
                }
            }
            finally
            {
                DnsResolver.Bind();
            }
        }