From f84362cc768d586262f5ddf8a21e74b932ef9420 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Tue, 21 Feb 2017 16:15:32 -0800 Subject: [PATCH] one last try to get this test de-flaked (#227) --- .../WebSocketConnection.cs | 3 ++- .../WebSocketConnectionTests.ConnectionLifecycle.cs | 1 - .../WebSocketConnectionTests.PingPong.cs | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Extensions.WebSockets.Internal/WebSocketConnection.cs b/src/Microsoft.Extensions.WebSockets.Internal/WebSocketConnection.cs index b04673642f..4942fdef2b 100644 --- a/src/Microsoft.Extensions.WebSockets.Internal/WebSocketConnection.cs +++ b/src/Microsoft.Extensions.WebSockets.Internal/WebSocketConnection.cs @@ -198,7 +198,8 @@ namespace Microsoft.Extensions.WebSockets.Internal { if (State == WebSocketConnectionState.Closed) { - throw new ObjectDisposedException(nameof(WebSocketConnection)); + // Already closed + return; } else if (State == WebSocketConnectionState.Created) { diff --git a/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.ConnectionLifecycle.cs b/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.ConnectionLifecycle.cs index cad82468ea..43fc25ba9a 100644 --- a/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.ConnectionLifecycle.cs +++ b/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.ConnectionLifecycle.cs @@ -123,7 +123,6 @@ namespace Microsoft.Extensions.WebSockets.Internal.Tests // Verify we can't restart the connection or send a message await Assert.ThrowsAsync(async () => await pair.ServerSocket.ExecuteAsync(f => { })); await Assert.ThrowsAsync(async () => await pair.ClientSocket.SendAsync(CreateTextFrame("Nope"))); - await Assert.ThrowsAsync(async () => await pair.ClientSocket.CloseAsync(new WebSocketCloseResult(WebSocketCloseStatus.NormalClosure))); } } diff --git a/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.PingPong.cs b/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.PingPong.cs index 9083f4272d..4534711f85 100644 --- a/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.PingPong.cs +++ b/test/Microsoft.Extensions.WebSockets.Internal.Tests/WebSocketConnectionTests.PingPong.cs @@ -22,7 +22,7 @@ namespace Microsoft.Extensions.WebSockets.Internal.Tests var startTime = DateTime.UtcNow; // Arrange using (var pair = WebSocketPair.Create( - serverOptions: new WebSocketOptions().WithAllFramesPassedThrough().WithPingInterval(TimeSpan.FromMilliseconds(100)), + serverOptions: new WebSocketOptions().WithAllFramesPassedThrough().WithPingInterval(TimeSpan.FromMilliseconds(10)), clientOptions: new WebSocketOptions().WithAllFramesPassedThrough())) { var client = pair.ClientSocket.ExecuteAndCaptureFramesAsync(); @@ -47,8 +47,7 @@ namespace Microsoft.Extensions.WebSockets.Internal.Tests var str = Encoding.UTF8.GetString(f.Payload.ToArray()); // We can't verify the exact timestamp, but we can verify that it is a timestamp created after we started. - DateTime dt; - if (DateTime.TryParseExact(str, "O", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out dt)) + if (DateTime.TryParseExact(str, "O", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var dt)) { return dt >= startTime; }