From 7418785a5e51fa0bc3e08840aa5fca52c286c49c Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Thu, 31 Aug 2017 15:30:55 -0700 Subject: [PATCH] Fix WebSocket race in E2E test (#809) --- .../EndToEndTests.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index 2024780854..292d6c4d10 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -157,7 +157,18 @@ namespace Microsoft.AspNetCore.SignalR.Tests } logger.LogInformation("Sending {length} byte message", bytes.Length); - await connection.SendAsync(bytes).OrTimeout(); + try + { + await connection.SendAsync(bytes).OrTimeout(); + } + catch (OperationCanceledException) + { + // Because the server and client are run in the same process there is a race where websocket.SendAsync + // can send a message but before returning be suspended allowing the server to run the EchoEndpoint and + // send a close frame which triggers a cancellation token on the client and cancels the websocket.SendAsync. + // Our solution to this is to just catch OperationCanceledException from the sent message if the race happens + // because we know the send went through, and its safe to check the response. + } logger.LogInformation("Sent message", bytes.Length); logger.LogInformation("Receiving message");