Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Root cause System.Net.Requests test failures on NETFX - #18801

Merged
davidsh merged 2 commits into
dotnet:masterfrom
davidsh:requests_netfx
Apr 24, 2017
Merged

davidsh merged 2 commits into
dotnet:masterfrom
davidsh:requests_netfx

Conversation

@davidsh

@davidsh davidsh commented Apr 24, 2017

Copy link
Copy Markdown
Contributor

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.

@davidsh davidsh added area-System.Net test-run-desktop Test failures in .NET Framework "Desktop" test runs (running CoreFX test assets) labels Apr 24, 2017
@davidsh davidsh added this to the 2.0.0 milestone Apr 24, 2017
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.
@davidsh

davidsh commented Apr 24, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test outerloop netcoreapp Windows_NT Debug
@dotnet-bot test outerloop netcoreapp Ubuntu16.04 Debug

HttpWebResponse hwr = (HttpWebResponse)response;

Assert.Throws<PlatformNotSupportedException>(() => formatter.Serialize(fs, hwr));
if (PlatformDetection.IsFullFramework)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// HttpWebResponse is not serializable on Core

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment.

HttpWebResponse httpResponse = (HttpWebResponse)response;
httpResponse.Close();
Assert.Throws<ObjectDisposedException>(() =>
if (PlatformDetection.IsFullFramework)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment explaining the bheavioral change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the response Stream usable in this state in desktop? If so, seems like one we should fix in core.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened new issue #18851

Assert.Throws<PlatformNotSupportedException>(() => formatter.Serialize(fs, hwr));
if (PlatformDetection.IsFullFramework)
{
// .NET Framework throws a more detailed exception.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be easy for us to modify HWRequest to throw SE. Should we?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added issue #18850

@danmoseley danmoseley left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it woudl be great to have a note (explaining reason or else with issue #) wherever behavior diverges. It comes up so often, and if it's noted in the tests, it helps.

Assert.Throws<PlatformNotSupportedException>(() => formatter.Serialize(fs, hwr));
if (PlatformDetection.IsFullFramework)
{
// .NET Framework throws a more detailed exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these asserts need to be removed? We're populating the content length and type in core but not in desktop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is referring to the fix made in #12231. If so, might want to include the PR link or number.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you include a short comment as to why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment to explain the difference on .NET Framework.

private Exception _savedResponseException = null;

private int _requestStreamCallbackCallCount = 0;
private int _responseCallbackCallCount = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@davidsh davidsh Apr 24, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should we add:

request.EndGetResponse(asyncResult).Dispose();

after this? (Same anywhere else we want to dispose of resources.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine change, but I'm curious... was the lack of this breaking something with desktop and passing with core?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@davidsh

davidsh commented Apr 24, 2017

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test outerloop netcoreapp Windows_NT Debug
@dotnet-bot test outerloop netcoreapp Ubuntu16.04 Debug

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net test-run-desktop Test failures in .NET Framework "Desktop" test runs (running CoreFX test assets)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants