Skip to content

Commit

Permalink
Fixed fallout from adding DisposeAsync to ConnectionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed May 27, 2019
1 parent 77d3c27 commit 4977f1b
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class HubConnectionTests : FunctionalTestBase

var delegateConnectionFactory = new DelegateConnectionFactory(
GetHttpConnectionFactory(url, loggerFactory, path, transportType ?? HttpTransportType.LongPolling | HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents),
connection => ((HttpConnection)connection).DisposeAsync());
connection => ((HttpConnection)connection).DisposeAsync().AsTask());
hubConnectionBuilder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);

return hubConnectionBuilder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private static HubConnection CreateHubConnection(TestConnection connection, IHub

var delegateConnectionFactory = new DelegateConnectionFactory(
connection.StartAsync,
c => ((TestConnection)c).DisposeAsync());
c => c.DisposeAsync().AsTask());

builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task ClosedEventRaisedWhenTheClientIsStopped()

var delegateConnectionFactory = new DelegateConnectionFactory(
format => new TestConnection().StartAsync(format),
connection => ((TestConnection)connection).DisposeAsync());
connection => ((TestConnection)connection).DisposeAsync().AsTask());
builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);

var hubConnection = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public TestConnection(Func<Task> onStart = null, Func<Task> onDispose = null, bo
null);
}

public Task DisposeAsync() => DisposeCoreAsync();
public override ValueTask DisposeAsync() => DisposeCoreAsync();

public async Task<ConnectionContext> StartAsync(TransferFormat transferFormat = TransferFormat.Binary)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public void CompleteFromTransport(Exception ex = null)
Application.Output.Complete(ex);
}

private async Task DisposeCoreAsync(Exception ex = null)
private async ValueTask DisposeCoreAsync(Exception ex = null)
{
Interlocked.Increment(ref _disposeCount);
_disposed.TrySetResult(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class HttpConnection : Microsoft.AspNetCore.Connections.Connectio
bool Microsoft.AspNetCore.Connections.Features.IConnectionInherentKeepAliveFeature.HasInherentKeepAlive { get { throw null; } }
public override System.IO.Pipelines.IDuplexPipe Transport { get { throw null; } set { } }
[System.Diagnostics.DebuggerStepThroughAttribute]
public System.Threading.Tasks.Task DisposeAsync() { throw null; }
public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
[System.Diagnostics.DebuggerStepThroughAttribute]
public System.Threading.Tasks.Task StartAsync(Microsoft.AspNetCore.Connections.TransferFormat transferFormat, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class HttpConnection : Microsoft.AspNetCore.Connections.Connectio
bool Microsoft.AspNetCore.Connections.Features.IConnectionInherentKeepAliveFeature.HasInherentKeepAlive { get { throw null; } }
public override System.IO.Pipelines.IDuplexPipe Transport { get { throw null; } set { } }
[System.Diagnostics.DebuggerStepThroughAttribute]
public System.Threading.Tasks.Task DisposeAsync() { throw null; }
public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
[System.Diagnostics.DebuggerStepThroughAttribute]
public System.Threading.Tasks.Task StartAsync(Microsoft.AspNetCore.Connections.TransferFormat transferFormat, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
10 changes: 10 additions & 0 deletions src/SignalR/common/testassets/Tests.Utils/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ static class TaskExtensions
{
private const int DefaultTimeout = 30 * 1000;

public static Task OrTimeout(this ValueTask task, int milliseconds = DefaultTimeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
{
return OrTimeout(task, new TimeSpan(0, 0, 0, 0, milliseconds), memberName, filePath, lineNumber);
}

public static Task OrTimeout(this ValueTask task, TimeSpan timeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
{
return task.AsTask().TimeoutAfter(timeout, filePath, lineNumber ?? 0);
}

public static Task OrTimeout(this Task task, int milliseconds = DefaultTimeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
{
return OrTimeout(task, new TimeSpan(0, 0, 0, 0, milliseconds), memberName, filePath, lineNumber);
Expand Down
4 changes: 2 additions & 2 deletions src/SignalR/samples/ClientSample/Tcp/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public TcpConnection(EndPoint endPoint)
// We claim to have inherent keep-alive so the client doesn't kill the connection when it hasn't seen ping frames.
public bool HasInherentKeepAlive { get; } = true;

public Task DisposeAsync()
public override ValueTask DisposeAsync()
{
Transport?.Output.Complete();
Transport?.Input.Complete();

_socket?.Dispose();

return Task.CompletedTask;
return default;
}

public async Task<ConnectionContext> StartAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Task<ConnectionContext> ConnectAsync(TransferFormat transferFormat, Cance

public Task DisposeAsync(ConnectionContext connection)
{
return ((TcpConnection)connection).DisposeAsync();
return connection.DisposeAsync().AsTask();
}
}
}
Expand Down

0 comments on commit 4977f1b

Please sign in to comment.