Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorMarcos Henrich <marcoshenrich@gmail.com>2015-09-03 16:02:57 +0300
committerMarcos Henrich <marcoshenrich@gmail.com>2015-09-03 16:02:57 +0300
commit097409cdab4f046189c17d4bd9490c8aecbc5ef4 (patch)
tree214e5050307147f2532c96c5ccac442bf78f6860 /mcs
parent30d65675fbbf23e816b2b18909ceb380b6cacdf3 (diff)
parent3445e2cf4e790c05f6887e7529b0b03ade5d2306 (diff)
Merge pull request #2024 from BogdanovKirill/webrequesttest
[HttpWebRequestTest] New test to check that after reading 2 GB of data from web server HttpWebRequest still works
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/System/Test/System.Net/HttpWebRequestTest.cs66
1 files changed, 66 insertions, 0 deletions
diff --git a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs
index c4296c39e27..1cc131fd8fd 100644
--- a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs
+++ b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs
@@ -6,6 +6,7 @@
// Martin Willemoes Hansen (mwh@sysrq.dk)
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Andres G. Aragoneses (andres@7digital.com)
+// Bogdanov Kirill (bogdanov@macroscop.com)
//
// (C) 2003 Martin Willemoes Hansen
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com
@@ -24,6 +25,7 @@ using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
+using System.Reflection;
using Mono.Security.Authenticode;
#if !MOBILE
using Mono.Security.Protocol.Tls;
@@ -2301,6 +2303,70 @@ namespace MonoTests.System.Net
return;
}
+
+ [Test]
+ public void TestLargeDataReading ()
+ {
+ int near2GBStartPosition = rand.Next (int.MaxValue - 500, int.MaxValue);
+ AutoResetEvent readyGetLastPortionEvent = new AutoResetEvent (false);
+ Exception testException = null;
+
+ DoRequest (
+ (request, waitHandle) =>
+ {
+ try
+ {
+ const int timeoutMs = 5000;
+
+ request.Timeout = timeoutMs;
+ request.ReadWriteTimeout = timeoutMs;
+
+ WebResponse webResponse = request.GetResponse ();
+ Stream webResponseStream = webResponse.GetResponseStream ();
+ Assert.IsNotNull (webResponseStream, null, "#1");
+
+ Type webConnectionStreamType = webResponseStream.GetType ();
+ FieldInfo totalReadField = webConnectionStreamType.GetField ("totalRead", BindingFlags.NonPublic | BindingFlags.Instance);
+ Assert.IsNotNull (totalReadField, "#2");
+ totalReadField.SetValue (webResponseStream, near2GBStartPosition);
+
+ byte[] readBuffer = new byte[int.MaxValue - near2GBStartPosition];
+ Assert.AreEqual (webResponseStream.Read (readBuffer, 0, readBuffer.Length), readBuffer.Length, "#3");
+ readyGetLastPortionEvent.Set ();
+ Assert.Greater (webResponseStream.Read (readBuffer, 0, readBuffer.Length), 0, "#4");
+ readyGetLastPortionEvent.Set ();
+
+ webResponse.Close();
+ }
+ catch (Exception e)
+ {
+ testException = e;
+ }
+ finally
+ {
+ waitHandle.Set ();
+ }
+ },
+ processor =>
+ {
+ processor.Request.InputStream.Close ();
+
+ HttpListenerResponse response = processor.Response;
+ response.SendChunked = true;
+
+ Stream outputStream = response.OutputStream;
+ var writeBuffer = new byte[int.MaxValue - near2GBStartPosition];
+ outputStream.Write (writeBuffer, 0, writeBuffer.Length);
+ readyGetLastPortionEvent.WaitOne ();
+ outputStream.Write (writeBuffer, 0, writeBuffer.Length);
+ readyGetLastPortionEvent.WaitOne ();
+
+ response.Close();
+ });
+
+ if (testException != null)
+ throw testException;
+ }
void DoRequest (Action<HttpWebRequest, EventWaitHandle> request)
{