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

Conversation

@Priya91
Copy link
Contributor

@Priya91 Priya91 commented Dec 14, 2017

cc @karelz @wfurt @davidsh

fixes #25878
fixes #25892

When any test with remote server dependency fails, it will output something like this:

System.Net.Http.Functional.Tests.HttpClientHandler_SslProtocols_Test.GetAsync_UnsupportedSSLVersion_Throws(name: \"SSLv2\", url: \"https://www.ssllabs.com:10200/\") [FAIL]
System.Net.Test.Common.RemoteServerException : Likely external issue with remote server : https://www.ssllabs.com:10200/
---- System.Net.Http.HttpRequestException : An error occurred while sending the request.
-------- System.Net.Http.WinHttpException : A connection with the server could not be established
Stack Trace:
   E:\corefx\src\Common\tests\System\Net\RemoteServerQuery.cs(65,0): at System.Net.Test.Common.RemoteServerQuery.<ThrowsAsync>d__1`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
   E:\corefx\src\System.Net.Http\tests\FunctionalTests\HttpClientHandlerTest.SslProtocols.cs(220,0): at System.Net.Http.Functional.Tests.HttpClientHandler_SslProtocols_Test.<GetAsync_UnsupportedSSLVersion_Throws>d__9.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
   --- End of stack trace from previous location where exception was thrown ---
   --- End of stack trace from previous location where exception was thrown ---
   ----- Inner Stack Trace -----
   E:\corefx\src\System.Net.Http\src\System\Net\Http\HttpClient.cs(464,0): at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
   E:\corefx\src\Common\tests\System\Net\RemoteServerQuery.cs(56,0): at System.Net.Test.Common.RemoteServerQuery.<ThrowsAsync>d__1`1.MoveNext()
   ----- Inner Stack Trace -----
   E:\corefx\src\System.Runtime.Extensions\src\System\Environment.cs(176,0): at System.Environment.get_StackTrace()
   E:\corefx\src\Common\src\System\Runtime\ExceptionServices\ExceptionStackTrace.cs(23,0): at System.Runtime.ExceptionServices.ExceptionStackTrace.AddCurrentStack(Exception exception)
   E:\corefx\src\Common\src\System\Net\Http\WinHttpException.cs(56,0): at System.Net.Http.WinHttpException.CreateExceptionUsingError(Int32 error)
   E:\corefx\src\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpRequestCallback.cs(324,0): at System.Net.Http.WinHttpRequestCallback.OnRequestError(WinHttpRequestState state, WINHTTP_ASYNC_RESULT asyncResult)
   E:\corefx\src\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpRequestCallback.cs(104,0): at System.Net.Http.WinHttpRequestCallback.RequestCallback(IntPtr handle, WinHttpRequestState state, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   E:\corefx\src\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpRequestCallback.cs(47,0): at System.Net.Http.WinHttpRequestCallback.WinHttpCallback(IntPtr handle, IntPtr context, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   --- End of stack trace from AddCurrentStack ---
   E:\corefx\src\Common\src\System\Threading\Tasks\RendezvousAwaitable.cs(62,0): at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
   E:\corefx\src\System.Net.Http.WinHttpHandler\src\System\Net\Http\WinHttpHandler.cs(856,0): at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()

@Priya91
Copy link
Contributor Author

Priya91 commented Dec 14, 2017

@dotnet-bot test outerloop linux x64 debug build please
@dotnet-bot test outerloop windows x64 debug build please
@dotnet-bot test outerloop osx x64 debug build please

@davidsh davidsh added area-System.Net test enhancement Improvements of test source code labels Dec 14, 2017
@Priya91
Copy link
Contributor Author

Priya91 commented Dec 14, 2017

The test failures are not related to this PR.

@wfurt
Copy link
Member

wfurt commented Dec 14, 2017

It looks ok to me. With "Likely external issue with remote server", would it make sense to claim it only on specific underlying exceptions e.g. timeout and reset?

@Priya91
Copy link
Contributor Author

Priya91 commented Dec 14, 2017

would it make sense to claim it only on specific underlying exceptions e.g. timeout and reset?

Yes, that's what the lambda you pass in to the API is for, only when the lambda returns true, the remoteserverexception is thrown.

public RemoteServerException()
: this(null, null) { }

public RemoteServerException(string server)
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this overload? - to force everyone to use the original exception as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

public RemoteServerException(string server, Exception inner)
: base(GetMessage(server), inner) { }

public static string GetMessage(string server)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like helper method, do we need it public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not exposed in any api or anything, the whole class in internal. But yeah it can be private.

using (HttpClient client = CreateHttpClient())
{
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync(url));
await RemoteServerQuery.ThrowsAsync<HttpRequestException>(() => client.GetAsync(url), remoteServerExceptionWrapper, url);
Copy link
Member

Choose a reason for hiding this comment

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

What if we just wrap the exception around the call?

await Assert.ThrowsAsync<HttpRequestException>(() => RemoteServerQuery.Run(() => client.GetAsync(url), remoteServerExceptionWrapper, url));


internal static async Task ThrowsAsync<T>(Func<Task> testCode, Func<Exception, bool> remoteExceptionWrapper, string serverName)
where T : Exception
{
Copy link
Member

Choose a reason for hiding this comment

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

We're now playing the role of XUnit a bit by comparing the exception type and not its subtypes (it may be xunit default behavior). Do we really need it? What if we stick to just wrapping the exception? (see next comment)

@karelz karelz removed the test enhancement Improvements of test source code label Dec 14, 2017
@Priya91
Copy link
Contributor Author

Priya91 commented Dec 15, 2017

the desktop run failed with

15:27:30 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(484,5): warning MSB3073: The command "D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.IO.Compression.Tests/netfx-Windows_NT-Release-x86//RunTests.cmd D:\j\workspace\windows-TGrou---2a8f9c29\bin/testhost/netfx-Windows_NT-Release-x86/" exited with code 1. [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.IO.Compression\tests\System.IO.Compression.Tests.csproj]
15:27:30 D:\j\workspace\windows-TGrou---2a8f9c29\Tools\tests.targets(492,5): error : One or more tests failed while running tests from 'System.IO.Compression.Tests' please check D:\j\workspace\windows-TGrou---2a8f9c29\bin/tests/System.IO.Compression.Tests/netfx-Windows_NT-Release-x86/testResults.xml for details! [D:\j\workspace\windows-TGrou---2a8f9c29\src\System.IO.Compression\tests\System.IO.Compression.Tests.csproj]

@Priya91 Priya91 merged commit 2fe2cd5 into dotnet:master Dec 15, 2017
@Priya91 Priya91 deleted the remoteserver branch December 15, 2017 01:03
@karelz karelz added this to the 2.1.0 milestone Dec 28, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Use generic test handling for remote server failures.

Commit migrated from dotnet/corefx@2fe2cd5
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

4 participants