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
ServicePoint google = ServicePointManager.FindServicePoint (new Uri ("http://www.google.com"));\r
try { \r
ServicePoint slashdot = ServicePointManager.FindServicePoint (new Uri ("http://www.slashdot.org"));\r
- Assertion.Fail ("#1");\r
+ Assert.Fail ("#1");\r
} catch (InvalidOperationException) { }\r
ServicePointManager.MaxServicePoints = 0;\r
\r
HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
HttpWebResponse res = (HttpWebResponse) req.GetResponse (); \r
\r
+#if FOUND_SOME_OTHER_URL
+ // URL is no longer found, disabled the test until a more reliable URL is found :P
//WriteServicePoint ("google after getting a response", google);\r
ServicePoint google2 = ServicePointManager.FindServicePoint (new Uri ("http://www.google.com/dilbert.html"));\r
- Assertion.AssertEquals ("#equals", google, google2);\r
+ Assert.AreEqual (google, google2, "#equals");\r
res.Close ();\r
+#endif
\r
// in both instances property CurrentConnections is 0 according to ms.net.\r
// let's see what it says when we do async operations...\r
//Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
res2.Close ();\r
\r
- \r
+ ServicePoint sp2;
+#if FOUND_SOME_OTHER_URL
// unless of course some buffering is taking place.. let's check\r
Uri uri2 = new Uri ("http://freedesktop.org/Software/pkgconfig/releases/pkgconfig-0.15.0.tar.gz");\r
- ServicePoint sp2 = ServicePointManager.FindServicePoint (uri2);\r
+ sp2 = ServicePointManager.FindServicePoint (uri2);\r
req2 = (HttpWebRequest) WebRequest.Create (uri2);\r
async = req2.BeginGetResponse (null, null);\r
//WriteServicePoint ("Large file: after async BeginGetResponse", sp2);\r
// and so it shows\r
//Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
res2.Close ();\r
+#endif
\r
\r
// what's the limit of the cache?\r
}\r
}\r
\r
+ [Test]\r
+ [Category ("InetAccess")]\r
+ [Category ("AndroidNotWorking")] // #A1 fails
+ public void EndPointBind ()\r
+ {\r
+ Uri uri = new Uri ("http://www.go-mono.com/");\r
+ ServicePoint sp = ServicePointManager.FindServicePoint (uri);\r
+\r
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create (uri);\r
+\r
+ bool called = false;\r
+ sp.BindIPEndPointDelegate = delegate {\r
+ Assert.IsTrue (!called);\r
+ called = true;\r
+ return null;\r
+ };\r
+ req.GetResponse ().Close ();\r
+\r
+ Assert.IsTrue (called, "#A1");\r
+\r
+ req = (HttpWebRequest) WebRequest.Create (uri);\r
+ called = false;\r
+ sp.BindIPEndPointDelegate = delegate(ServicePoint point, IPEndPoint remote, int times) {\r
+ Assert.IsTrue (times < 5);\r
+ called = true;\r
+ return new IPEndPoint(IPAddress.Parse("0.0.0.0"), 12345 + times);\r
+ };\r
+ req.GetResponse ().Close ();\r
+\r
+ Assert.IsTrue (called, "#A2");\r
+ }\r
+\r
+ public static void GetRequestStreamCallback (IAsyncResult asynchronousResult)\r
+ {\r
+ }\r
+\r
+ [Test] //Covers #19823\r
+ public void CloseConnectionGroupConcurency ()\r
+ {\r
+ // Try with multiple service points\r
+ for (var i = 0; i < 10; i++) {\r
+ Uri targetUri = new Uri ("http://" + i + ".mono-project.com");\r
+ var req = (HttpWebRequest) HttpWebRequest.Create (targetUri);\r
+ req.ContentType = "application/x-www-form-urlencoded";\r
+ req.Method = "POST";\r
+ req.ConnectionGroupName = "" + i;\r
+ req.ServicePoint.MaxIdleTime = 1;\r
+\r
+ req.BeginGetRequestStream (new AsyncCallback (GetRequestStreamCallback), req);\r
+ Thread.Sleep (1);\r
+ req.ServicePoint.CloseConnectionGroup (req.ConnectionGroupName);\r
+ }\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