Merge pull request #3106 from lambdageek/dev/monoerror-unhandled
[mono.git] / mcs / class / System / Test / System.Net / ServicePointTest.cs
index 8c564e246582ecea8532b770916867d45698898b..346f35bdeacd358202f49bad9a130cef91bd0066 100644 (file)
@@ -13,6 +13,7 @@ using System;
 using System.Collections;\r
 using System.IO;\r
 using System.Net;\r
+using System.Reflection;
 using System.Threading;\r
 \r
 namespace MonoTests.System.Net\r
@@ -205,6 +206,36 @@ public class ServicePointTest
                }\r
        }\r
 \r
+
+       [Test]
+       public void DnsRefreshTimeout ()
+       {
+               const int dnsRefreshTimeout = 2000;
+
+               ServicePoint sp;
+               IPHostEntry host0, host1, host2;
+               Uri uri;
+               PropertyInfo hostEntryProperty;
+
+               ServicePointManager.DnsRefreshTimeout = dnsRefreshTimeout;
+
+               uri = new Uri ("http://localhost/");
+               sp = ServicePointManager.FindServicePoint (uri);
+
+               hostEntryProperty = typeof (ServicePoint).GetProperty ("HostEntry", BindingFlags.NonPublic | BindingFlags.Instance);
+
+               host0 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
+               host1 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
+
+               Assert.AreSame (host0, host1, "HostEntry should result in the same IPHostEntry object.");
+
+               Thread.Sleep (dnsRefreshTimeout * 2);
+               host2 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
+
+               Assert.AreNotSame(host0, host2, "HostEntry should result in a new IPHostEntry " +
+                               "object when DnsRefreshTimeout is reached.");
+       }
+
 // Debug code not used now, but could be useful later\r
 /*\r
        private void WriteServicePoint (string label, ServicePoint sp)\r