Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

TestHost: support WebSocket testing #336

Closed
wants to merge 6 commits into from
Closed

TestHost: support WebSocket testing #336

wants to merge 6 commits into from

Conversation

tmds
Copy link
Contributor

@tmds tmds commented Aug 22, 2015

Implement #315

@dnfclas
Copy link

dnfclas commented Aug 22, 2015

Hi @tmds, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;


public async Task<WebSocket> ConnectAsync(Uri uri, CancellationToken cancellationToken)
{
HttpClient client = _testServer.CreateClient();
Copy link
Member

Choose a reason for hiding this comment

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

I think the WebSocketClient can bypass the HttpClient entirely. HttpClient doesn't have any concept of WebSockets, so tacking them on is pretty awkward. Instead of creating an HttpRequestMessage here just create an IFeatureCollection & DefaultHttpContext directly (This may be a little easer after aspnet/HttpAbstractions#367).

@tmds
Copy link
Contributor Author

tmds commented Aug 24, 2015

@Tratcher I re-implemented the feature based on your feedback
I still need to add the read/write test. Also, the WebSocket.Abort/Dispose logic needs to be checked.

@@ -66,22 +66,22 @@ public ClientHandler([NotNull] Func<IFeatureCollection, Task> next, PathString p

// Async offload, don't let the test code block the caller.
var offload = Task.Factory.StartNew(async () =>
{
Copy link
Member

Choose a reason for hiding this comment

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

You can revert this file if only the formatting has changed.

@Tratcher
Copy link
Member

This looks much better overall. It's definitely going to need some tests though.


Task<System.Net.WebSockets.WebSocket> IHttpWebSocketFeature.AcceptAsync(WebSocketAcceptContext context)
{
var websockets = WebSocket.CreatePair(context.SubProtocol);
Copy link
Member

Choose a reason for hiding this comment

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

Store both of these and abort/dispose them when _next finishes or throws (e.g. PipelineComplete or PipelineFailed).

- WebSocket: rename to TestWebSocket to avoid name clash with System.Net.WebSockets.WebSocket
- TestWebSocket: fully implement Close/Abort/Dispose logic
- TestClientTests: add tests for read/write, dispose and endofmessage
- WebSocketClient: dispose server websocket when pipeline ends
- WebSocketClient: immediately construct HttpRequest, drop HttpRequestMessage
@tmds
Copy link
Contributor Author

tmds commented Aug 24, 2015

@Tratcher, @davidfowl, I improved the code further based on your comments
Two points:

  • WebSocketClient disposes the server websocket when the pipeline ends. Disposing the client websocket is the responsibility of the client (i.e. the test)
  • I replaced HttpRequestMessage by HttpRequest for WebSocketClient.ConfigureRequest. I limited this to the request, as this is also the case for the real WebSocketClient.


namespace Microsoft.AspNet.TestHost
{
internal class TestWebSocket : System.Net.WebSockets.WebSocket
Copy link
Member

Choose a reason for hiding this comment

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

Do you still need the full type name here? System.Net.WebSockets.WebSocket

@@ -7,6 +7,10 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Xunit;
using System.Threading;
Copy link
Member

Choose a reason for hiding this comment

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

Sort, System first.

@tmds
Copy link
Contributor Author

tmds commented Aug 27, 2015

@Tratcher, is this ready for merging?

@Tratcher
Copy link
Member

@tmds Sorry, this is on hold while we resolve an internal discussion about WebSockets. We'll get back to you soon.

cc: @DamianEdwards

@tmds
Copy link
Contributor Author

tmds commented Aug 28, 2015

@Tratcher no problem, take your time

@Tratcher Tratcher added this to the 1.0.0-beta8 milestone Sep 1, 2015
@Tratcher
Copy link
Member

Tratcher commented Sep 1, 2015

:shipit: I'll try rebasing myself.

@Tratcher
Copy link
Member

Tratcher commented Sep 1, 2015

Rebased and merged.

@Tratcher Tratcher closed this Sep 1, 2015
@tmds tmds deleted the websocket branch September 2, 2015 18:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants