Repository navigation
Root cause System.Net.Requests test failures on NETFX - #18801
Conversation
Finished investigation of failures on .NET Framework for System.Net.Requests. Cleaned up some tests that used "global" variables in the test class. Since tests are running in parallel, that wasn't a good idea. Changed to use the state object passed into the BeginGet* methods (which is best practice). Added new bugs #18784, #18787 and #18800. Fixes #17842.
|
@dotnet-bot test outerloop netcoreapp Windows_NT Debug |
| HttpWebResponse hwr = (HttpWebResponse)response; | ||
|
|
||
| Assert.Throws<PlatformNotSupportedException>(() => formatter.Serialize(fs, hwr)); | ||
| if (PlatformDetection.IsFullFramework) |
There was a problem hiding this comment.
// HttpWebResponse is not serializable on Core
| HttpWebResponse httpResponse = (HttpWebResponse)response; | ||
| httpResponse.Close(); | ||
| Assert.Throws<ObjectDisposedException>(() => | ||
| if (PlatformDetection.IsFullFramework) |
There was a problem hiding this comment.
can you add a comment explaining the bheavioral change?
There was a problem hiding this comment.
Is the response Stream usable in this state in desktop? If so, seems like one we should fix in core.
There was a problem hiding this comment.
Opened new issue #18851
| Assert.Throws<PlatformNotSupportedException>(() => formatter.Serialize(fs, hwr)); | ||
| if (PlatformDetection.IsFullFramework) | ||
| { | ||
| // .NET Framework throws a more detailed exception. |
There was a problem hiding this comment.
It would be easy for us to modify HWRequest to throw SE. Should we?
There was a problem hiding this comment.
Binary Serialization is now supported on .NET Core 2.0 but it wasn't in 1.1 or 1.0; so probably that is why we were throwing PNSE, so I think the same thing, it sounds reasonable to throw SE.
| Assert.Throws<PlatformNotSupportedException>(() => formatter.Serialize(fs, hwr)); | ||
| if (PlatformDetection.IsFullFramework) | ||
| { | ||
| // .NET Framework throws a more detailed exception. |
There was a problem hiding this comment.
Binary Serialization is now supported on .NET Core 2.0 but it wasn't in 1.1 or 1.0; so probably that is why we were throwing PNSE, so I think the same thing, it sounds reasonable to throw SE.
| Assert.Equal(data.Length.ToString(), response.Headers[HttpRequestHeader.ContentLength]); | ||
|
|
||
| Assert.Equal("application/octet-stream", response.ContentType); | ||
| Assert.Equal("application/octet-stream", response.Headers[HttpRequestHeader.ContentType]); |
There was a problem hiding this comment.
Why do these asserts need to be removed? We're populating the content length and type in core but not in desktop?
There was a problem hiding this comment.
The asserts are invalid. They throw on Desktop. See #18784. Since this is a FileWebRequest, there are no 'Content-Length' nor 'Content-Type' headers. It is an invalid concept for a WebRequest that is a FileWebRequest.
| public abstract class AsyncFileWebRequestTestBase : FileWebRequestTestBase | ||
| { | ||
| [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "dotnet/corefx #17842")] | ||
| [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "concurrent read/write not supported on netfx")] |
There was a problem hiding this comment.
I assume this is referring to the fix made in #12231. If so, might want to include the PR link or number.
There was a problem hiding this comment.
Revised text in Skip attribute to include PR number.
| #pragma warning disable 0618 //GlobalProxySelection is Deprecated. | ||
| Assert.NotNull(GlobalProxySelection.Select); | ||
| Assert.Equal(GlobalProxySelection.Select, WebRequest.DefaultWebProxy); | ||
| if (!PlatformDetection.IsFullFramework) |
There was a problem hiding this comment.
Nit: could you include a short comment as to why?
There was a problem hiding this comment.
Added comment to explain the difference on .NET Framework.
| private Exception _savedResponseException = null; | ||
|
|
||
| private int _requestStreamCallbackCallCount = 0; | ||
| private int _responseCallbackCallCount = 0; |
There was a problem hiding this comment.
This is a good change, in that it's better to have this as local rather than instance state. I'm curious though why it was necessary... tests on the same instance are never run in parallel by xunit, with it creating a new instance per test method invocation.
There was a problem hiding this comment.
While I was fixing various hangs, etc., I made this change. After all the other fixes I made, it might be unnecessary.
You are right that Xunit creates a new test class instance per test method so these "instance" fields are not shared even though they are in the same test class. But a naive developer (like me) wouldn't figure that out right away. It is not intuitive. It's better to use the state variables as a best practice.
| { | ||
| _savedHttpWebRequest.BeginGetRequestStream(null, null); | ||
| request.BeginGetRequestStream(null, null); | ||
| }); |
There was a problem hiding this comment.
Can/should we add:
request.EndGetResponse(asyncResult).Dispose();after this? (Same anywhere else we want to dispose of resources.)
There was a problem hiding this comment.
I understand the concern that several of these tests starting network I/O with BeginGetResponse() but don't seem to finish it with EndGetResponse (i.e. via a callback etc.). I'd rather not complicate this PR by trying to add all of that now. The tests are currently stable.
| DateTimeOffset utcNow = DateTimeOffset.UtcNow; | ||
| await LoopbackServer.ReadRequestAndSendResponseAsync(server, | ||
| $"HTTP/1.1 200 OK\r\n" + | ||
| $"Date: {utcNow:R}\r\n" + |
There was a problem hiding this comment.
Fine change, but I'm curious... was the lack of this breaking something with desktop and passing with core?
There was a problem hiding this comment.
Yes. It was causing a hang on Desktop. I wasn't sure exactly why...but making it a correct HTTP response got rid of the problem.
|
@dotnet-bot test outerloop netcoreapp Windows_NT Debug |
Finished investigation of failures on .NET Framework for System.Net.Requests.
Cleaned up some tests that used "global" variables in the test class. Since
tests are running in parallel, that wasn't a good idea. Changed to use the
state object passed into the BeginGet* methods (which is best practice).
Added new bugs #18784, #18787 and #18800.
Fixes #17842.