Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / class / System / Test / System.Net / ServicePointTest.cs
index 16666cc6d8581632d9c0b2908be682481e1fb584..bb12a4c28f3eb93112b9ac5e1952a68b9c80fa4a 100644 (file)
@@ -44,7 +44,7 @@ public class ServicePointTest
                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
@@ -55,7 +55,7 @@ public class ServicePointTest
                \r
                //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
                \r
                // in both instances property CurrentConnections is 0 according to ms.net.\r
@@ -146,6 +146,59 @@ public class ServicePointTest
                }\r
        }\r
 \r
+       [Test]\r
+       [Category ("InetAccess")]\r
+       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);\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);\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
 // Debug code not used now, but could be useful later\r
 /*\r
        private void WriteServicePoint (string label, ServicePoint sp)\r