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

Add System.Net.WebSockets.Client tests - #4478

Merged
davidsh merged 1 commit into
dotnet:masterfrom
davidsh:websocket_tests
Nov 13, 2015
Merged

davidsh merged 1 commit into
dotnet:masterfrom
davidsh:websocket_tests

Conversation

@davidsh

@davidsh davidsh commented Nov 12, 2015

Copy link
Copy Markdown
Contributor
  • Port some of the ToF ClientWebSocket tests that talk to a real websocket server
  • Cleanup naming of existing tests to conform to System.Net test method naming
  • Skip tests if not supported on platform. Specifically, these tests were failing
    on Win7 since Win7 does not support WinHttp WebSockets. We haven't really noticed this
    failing since the CI doesn't yet run Win7 tests (issue #4468)

I plan to port the remainder of the ToF websocket related tests in a subsequent PR.

@davidsh

davidsh commented Nov 12, 2015

Copy link
Copy Markdown
Contributor Author

@CIPop @pgavlin @stephentoub PTAL

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This could be placed in Test\Common: we may want to use it in other tests.

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.

Fixed. Moved to src/Common/tests/System/AssertExtensions.cs

@CIPop

CIPop commented Nov 12, 2015

Copy link
Copy Markdown

LGTM

You may need to change the author to dotnet-bot since you are porting code from the internal repository.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: formatting should be:

if (WebSocketHelper.ShouldSkipTestOSNotSupported(_output))
{
    return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(same throughout)

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.

To be honest, I usually would have formatted like that (since I tell others to do so).

But it just seemed so wasteful in white space. What I really want is an Xunit attribute that can be added via some [Skip] attribute with PlatformID.Windows7. Or even better something more dynamic that does the same check for 'PlatformNotSupportedException'.

So, I can change the formatting to conform to our own rules, but I view it as temporary until we getting "skipping" capability in our tests.

@pgavlin

pgavlin commented Nov 12, 2015

Copy link
Copy Markdown
Contributor

LGTM aside from one nit regarding formatting. Thanks for porting these!

@davidsh

davidsh commented Nov 12, 2015

Copy link
Copy Markdown
Contributor Author

I will change author to dotnet-bot during final squash of commits.

* Port some of the ToF ClientWebSocket tests that talk to a real websocket server
* Cleanup naming of existing tests to conform to System.Net test method naming
* Skip tests if not supported on platform. Specifically, these tests were failing
on Win7 since Win7 does not support WinHttp WebSockets. We haven't really noticed this
failing since the CI doesn't yet run Win7 tests (issue #4468)

I plan to port the remainder of the ToF websocket related tests in a subsequent PR.

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.

Should this be disposed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As with Sockets: these tests use bad dev patterns to ensure that in certain cases the objects get GCed with no issues.
We don't expect FunctionalTests to be deterministic.

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 think we're slightly inconsistent on this point because the Http tests, for the most part, show proper dev pattern and have Dispose or using patterns. The exception is when we are explicitly testing for certain behavior with various patterns of using/not-using Dispose.

With regard to these tests, some of the tests are explicitly testing against different Dispose semantics, i.e. call methods after Dispose, etc.

I'll make a note to be more explicit about this. I think we should be more consistent.

@stephentoub

Copy link
Copy Markdown
Member

I tried running these tests locally. About half of the time they pass, and about half of the time I get errors like this:

Discovering: System.Net.WebSockets.Client.Tests
  Discovered:  System.Net.WebSockets.Client.Tests
  Starting:    System.Net.WebSockets.Client.Tests
     System.Net.WebSockets.Client.Tests.ClientWebSocketTest.EchoBinaryMessage_Success(server: ws://corefx-networking.azurewebsites.net/WebSocket/EchoWebSocket.
  ashx) [FAIL]
        System.Net.WebSockets.WebSocketException : The 'System.Net.WebSockets.InternalClientWebSocket' instance cannot be used for communication because it has
   been transitioned into the 'Aborted' state.
        Stack Trace:
              at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
              at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
           c:\Users\stoub\Source\repos\corefx\src\System.Net.WebSockets.Client\src\System\Net\WebSockets\WinHttpWebSocket.cs(466,0): at System.Net.WebSockets.W
  inHttpWebSocket.<CloseAsync>d__32.MoveNext()
           --- End of stack trace from previous location where exception was thrown ---
              at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
           c:\Users\stoub\Source\repos\corefx\src\System.Net.WebSockets.Client\tests\WebSocketHelper.cs(86,0): at System.Net.WebSockets.Client.Tests.WebSocketH
  elper.<TestEcho>d__5.MoveNext()
           --- End of stack trace from previous location where exception was thrown ---
              at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
           c:\Users\stoub\Source\repos\corefx\src\System.Net.WebSockets.Client\tests\ClientWebSocketTest.cs(38,0): at System.Net.WebSockets.Client.Tests.Client
  WebSocketTest.<EchoBinaryMessage_Success>d__4.MoveNext()
           --- End of stack trace from previous location where exception was thrown ---
              at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           --- End of stack trace from previous location where exception was thrown ---
              at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           --- End of stack trace from previous location where exception was thrown ---
              at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
              at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  Finished:    System.Net.WebSockets.Client.Tests

@davidsh

davidsh commented Nov 13, 2015

Copy link
Copy Markdown
Contributor Author

I tried running these tests locally. About half of the time they pass, and about half of the time I get errors like this:

What OS and version are you using?

@stephentoub

Copy link
Copy Markdown
Member

What OS and version are you using?

OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.10240 N/A Build 10240

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've never actually looked into this until now, but seeing each of these tests begin with this boilerplate made me want to see if xunit extensibility could be employed here. Instead of using this boilerplate in each test, I just tried adding this code to the project:

[XunitTestCaseDiscoverer("System.Net.WebSockets.Client.Tests.RequiresWebSocketsFactDiscoverer", "System.Net.WebSockets.Client.Tests")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class RequiresWebSocketsFact : FactAttribute { }

public class RequiresWebSocketsFactDiscoverer : IXunitTestCaseDiscoverer
{
    private readonly IMessageSink _diagnosticMessageSink;

    public RequiresWebSocketsFactDiscoverer(IMessageSink diagnosticMessageSink)
    {
        _diagnosticMessageSink = diagnosticMessageSink;
    }

    public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
    {
        return WebSocketsHelper.WebSocketsIsSupported ?
            new IXunitTestCase[] { new XunitTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, null) } :
            Array.Empty<IXunitTestCase>();
    }
}

and then instead of this boilerplate at the beginning of each method, I was able to attribute each test with:

[RequiresWebSocketsFact]

instead of:

[Fact]

Something to consider.

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.

@stephentoub Thx. I like this. But how would it work for Theory instead of Fact ?

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 think you'd need to add a RequiresWebSocketsTheoryAttribute and associated discoverer as well.

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 will work on this extensions attributes as part of the next WebSockets PR I'll be doing.

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.

Cool. We should also be able to generalize it to some sort of [ConditionalFact("MethodThatReturnsBoolean")] and the same for theory, which we could put in our xunit extensions and then use elsewhere.

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.

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'm working on adding something to buildtools. Don't block on it, though.

@davidsh

davidsh commented Nov 13, 2015

Copy link
Copy Markdown
Contributor Author

@davidsh

davidsh commented Nov 13, 2015

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test this please

@davidsh

davidsh commented Nov 13, 2015

Copy link
Copy Markdown
Contributor Author

Unrelated CI failure:http://dotnet-ci.cloudapp.net/job/dotnet_corefx_prtest/6389/

System.Net.Security.Tests.ClientAsyncAuthenticateTest.ClientAsyncAuthenticate_EachProtocol_Success
System.Net.Security.Tests.CertificateValidationClientServer.CertificateValidationClientServer_EndToEnd_Ok
System.Net.Security.Tests.SslStreamStreamToStreamTest.SslStream_StreamToStream_Authentication_Success

@davidsh

davidsh commented Nov 13, 2015

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test this please

@stephentoub

Copy link
Copy Markdown
Member

Unrelated CI failure

Looks like the same three that failed here: https://github.com/dotnet/corefx/issues/4467

davidsh added a commit that referenced this pull request Nov 13, 2015
Add System.Net.WebSockets.Client tests
@davidsh
davidsh merged commit e17dd58 into dotnet:master Nov 13, 2015
@davidsh
davidsh deleted the websocket_tests branch November 13, 2015 17:26
@karelz karelz added port-to-core Issue tracking port of .NET Framework code to .NET Core and removed Port to GitHub labels Nov 9, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Add System.Net.WebSockets.Client tests

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

Labels

area-System.Net port-to-core Issue tracking port of .NET Framework code to .NET Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants