prevent websocket deadlock (#419)

This commit is contained in:
Andrew Stanton-Nurse 2017-04-25 15:18:47 -07:00 committed by GitHub
parent 9e13f0fdb0
commit 5aea7292cd
2 changed files with 5 additions and 3 deletions

View File

@ -1,11 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO.Pipelines;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets;
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests
{ {
public class EchoEndPoint : EndPoint public class EchoEndPoint : EndPoint

View File

@ -92,6 +92,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
try try
{ {
var receiveTcs = new TaskCompletionSource<string>(); var receiveTcs = new TaskCompletionSource<string>();
var closeTcs = new TaskCompletionSource<object>();
connection.Received += (data, format) => connection.Received += (data, format) =>
{ {
logger.LogInformation("Received {length} byte message", data.Length); logger.LogInformation("Received {length} byte message", data.Length);
@ -108,6 +109,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{ {
receiveTcs.TrySetResult(null); receiveTcs.TrySetResult(null);
} }
closeTcs.TrySetResult(null);
}; };
logger.LogInformation("Starting connection to {url}", url); logger.LogInformation("Starting connection to {url}", url);
@ -124,6 +126,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
logger.LogInformation("Receiving message"); logger.LogInformation("Receiving message");
Assert.Equal(message, await receiveTcs.Task.OrTimeout()); Assert.Equal(message, await receiveTcs.Task.OrTimeout());
logger.LogInformation("Completed receive"); logger.LogInformation("Completed receive");
await closeTcs.Task.OrTimeout();
} }
finally finally
{ {