Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser] reduce System.Net.WebSockets.Client.Tests noise in log files #97654

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ public async Task Proxy_ConnectThruProxy_Success(Uri server)
string proxyServerUri = System.Net.Test.Common.Configuration.WebSockets.ProxyServerUri;
if (string.IsNullOrEmpty(proxyServerUri))
{
_output.WriteLine("Skipping test...no proxy server defined.");
Copy link
Member

Choose a reason for hiding this comment

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

This should probably instead be throw new SkipTestException("No proxy server defined.");

return;
}

_output.WriteLine($"ProxyServer: {proxyServerUri}");

IWebProxy proxy = new WebProxy(new Uri(proxyServerUri));
using (ClientWebSocket cws = await WebSocketHelper.GetConnectedWebSocket(
server,
Expand Down
6 changes: 0 additions & 6 deletions src/libraries/System.Net.WebSockets.Client/tests/CloseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,14 @@ public async Task CloseAsync_ServerInitiatedClose_Success(Uri server, bool useCl
{
var cts = new CancellationTokenSource(TimeOutMilliseconds);

_output.WriteLine("SendAsync starting.");
await cws.SendAsync(
WebSocketData.GetBufferFromText(shutdownWebSocketMetaCommand),
WebSocketMessageType.Text,
true,
cts.Token);
_output.WriteLine("SendAsync done.");

var recvBuffer = new byte[256];
_output.WriteLine("ReceiveAsync starting.");
WebSocketReceiveResult recvResult = await cws.ReceiveAsync(new ArraySegment<byte>(recvBuffer), cts.Token);
_output.WriteLine("ReceiveAsync done.");

// Verify received server-initiated close message.
Assert.Equal(WebSocketCloseStatus.NormalClosure, recvResult.CloseStatus);
Expand All @@ -68,12 +64,10 @@ await cws.SendAsync(
Assert.Equal(shutdownWebSocketMetaCommand, cws.CloseStatusDescription);

// Send back close message to acknowledge server-initiated close.
_output.WriteLine("Close starting.");
var closeStatus = PlatformDetection.IsNotBrowser ? WebSocketCloseStatus.InvalidMessageType : (WebSocketCloseStatus)3210;
await (useCloseOutputAsync ?
cws.CloseOutputAsync(closeStatus, string.Empty, cts.Token) :
cws.CloseAsync(closeStatus, string.Empty, cts.Token));
_output.WriteLine("Close done.");
Assert.Equal(WebSocketState.Closed, cws.State);

// Verify that there is no follow-up echo close message back from the server by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ public async Task ConnectAsync_PassNoSubProtocol_ServerRequires_ThrowsWebSocketE

WebSocketException ex = await Assert.ThrowsAsync<WebSocketException>(() =>
ConnectAsync(cws, ub.Uri, cts.Token));
_output.WriteLine(ex.Message);
Assert.True(ex.WebSocketErrorCode == WebSocketError.Faulted ||
ex.WebSocketErrorCode == WebSocketError.NotAWebSocket, $"Actual WebSocketErrorCode {ex.WebSocketErrorCode} {ex.InnerException?.Message} \n {ex}");
Assert.Equal(WebSocketState.Closed, cws.State);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ public static async Task TestEcho(

using (ClientWebSocket cws = await GetConnectedWebSocket(server, timeOutMilliseconds, output, invoker: invoker))
{
output.WriteLine("TestEcho: SendAsync starting.");
await cws.SendAsync(WebSocketData.GetBufferFromText(message), type, true, cts.Token);
output.WriteLine("TestEcho: SendAsync done.");
Assert.Equal(WebSocketState.Open, cws.State);

output.WriteLine("TestEcho: ReceiveAsync starting.");
WebSocketReceiveResult recvRet = await cws.ReceiveAsync(receiveSegment, cts.Token);
output.WriteLine("TestEcho: ReceiveAsync done.");
Assert.Equal(WebSocketState.Open, cws.State);
Assert.Equal(message.Length, recvRet.Count);
Assert.Equal(type, recvRet.MessageType);
Expand All @@ -49,14 +45,12 @@ public static async Task TestEcho(
var recvSegment = new ArraySegment<byte>(receiveSegment.Array, receiveSegment.Offset, recvRet.Count);
Assert.Equal(message, WebSocketData.GetTextFromBuffer(recvSegment));

output.WriteLine("TestEcho: CloseAsync starting.");
Task taskClose = cws.CloseAsync(WebSocketCloseStatus.NormalClosure, closeMessage, cts.Token);
Assert.True(
(cws.State == WebSocketState.Open) || (cws.State == WebSocketState.CloseSent) ||
(cws.State == WebSocketState.CloseReceived) || (cws.State == WebSocketState.Closed),
"State immediately after CloseAsync : " + cws.State);
await taskClose;
output.WriteLine("TestEcho: CloseAsync done.");
Assert.Equal(WebSocketState.Closed, cws.State);
Assert.Equal(WebSocketCloseStatus.NormalClosure, cws.CloseStatus);
Assert.Equal(closeMessage, cws.CloseStatusDescription);
Expand Down Expand Up @@ -85,7 +79,6 @@ public static Task<ClientWebSocket> GetConnectedWebSocket(

using (var cts = new CancellationTokenSource(timeOutMilliseconds))
{
output.WriteLine("GetConnectedWebSocket: ConnectAsync starting.");
Task taskConnect = invoker == null ? cws.ConnectAsync(server, cts.Token) : cws.ConnectAsync(server, invoker, cts.Token);
Assert.True(
(cws.State == WebSocketState.None) ||
Expand All @@ -94,7 +87,6 @@ public static Task<ClientWebSocket> GetConnectedWebSocket(
(cws.State == WebSocketState.Aborted),
"State immediately after ConnectAsync incorrect: " + cws.State);
await taskConnect;
output.WriteLine("GetConnectedWebSocket: ConnectAsync done.");
Assert.Equal(WebSocketState.Open, cws.State);
}
return cws;
Expand Down
Loading