Skip to content

Commit 4977f1b

Browse files
committed
Fixed fallout from adding DisposeAsync to ConnectionContext
1 parent 77d3c27 commit 4977f1b

File tree

9 files changed

+20
-10
lines changed

9 files changed

+20
-10
lines changed

src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private HubConnection CreateHubConnection(
5959

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

6565
return hubConnectionBuilder.Build();

src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private static HubConnection CreateHubConnection(TestConnection connection, IHub
1616

1717
var delegateConnectionFactory = new DelegateConnectionFactory(
1818
connection.StartAsync,
19-
c => ((TestConnection)c).DisposeAsync());
19+
c => c.DisposeAsync().AsTask());
2020

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

src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public async Task ClosedEventRaisedWhenTheClientIsStopped()
6363

6464
var delegateConnectionFactory = new DelegateConnectionFactory(
6565
format => new TestConnection().StartAsync(format),
66-
connection => ((TestConnection)connection).DisposeAsync());
66+
connection => ((TestConnection)connection).DisposeAsync().AsTask());
6767
builder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);
6868

6969
var hubConnection = builder.Build();

src/SignalR/clients/csharp/Client/test/UnitTests/TestConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public TestConnection(Func<Task> onStart = null, Func<Task> onDispose = null, bo
6060
null);
6161
}
6262

63-
public Task DisposeAsync() => DisposeCoreAsync();
63+
public override ValueTask DisposeAsync() => DisposeCoreAsync();
6464

6565
public async Task<ConnectionContext> StartAsync(TransferFormat transferFormat = TransferFormat.Binary)
6666
{
@@ -195,7 +195,7 @@ public void CompleteFromTransport(Exception ex = null)
195195
Application.Output.Complete(ex);
196196
}
197197

198-
private async Task DisposeCoreAsync(Exception ex = null)
198+
private async ValueTask DisposeCoreAsync(Exception ex = null)
199199
{
200200
Interlocked.Increment(ref _disposeCount);
201201
_disposed.TrySetResult(null);

src/SignalR/clients/csharp/Http.Connections.Client/ref/Microsoft.AspNetCore.Http.Connections.Client.netcoreapp3.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public HttpConnection(System.Uri url, Microsoft.AspNetCore.Http.Connections.Http
1515
bool Microsoft.AspNetCore.Connections.Features.IConnectionInherentKeepAliveFeature.HasInherentKeepAlive { get { throw null; } }
1616
public override System.IO.Pipelines.IDuplexPipe Transport { get { throw null; } set { } }
1717
[System.Diagnostics.DebuggerStepThroughAttribute]
18-
public System.Threading.Tasks.Task DisposeAsync() { throw null; }
18+
public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
1919
[System.Diagnostics.DebuggerStepThroughAttribute]
2020
public System.Threading.Tasks.Task StartAsync(Microsoft.AspNetCore.Connections.TransferFormat transferFormat, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2121
public System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }

src/SignalR/clients/csharp/Http.Connections.Client/ref/Microsoft.AspNetCore.Http.Connections.Client.netstandard2.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public HttpConnection(System.Uri url, Microsoft.AspNetCore.Http.Connections.Http
1515
bool Microsoft.AspNetCore.Connections.Features.IConnectionInherentKeepAliveFeature.HasInherentKeepAlive { get { throw null; } }
1616
public override System.IO.Pipelines.IDuplexPipe Transport { get { throw null; } set { } }
1717
[System.Diagnostics.DebuggerStepThroughAttribute]
18-
public System.Threading.Tasks.Task DisposeAsync() { throw null; }
18+
public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
1919
[System.Diagnostics.DebuggerStepThroughAttribute]
2020
public System.Threading.Tasks.Task StartAsync(Microsoft.AspNetCore.Connections.TransferFormat transferFormat, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2121
public System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }

src/SignalR/common/testassets/Tests.Utils/TaskExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ static class TaskExtensions
1717
{
1818
private const int DefaultTimeout = 30 * 1000;
1919

20+
public static Task OrTimeout(this ValueTask task, int milliseconds = DefaultTimeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
21+
{
22+
return OrTimeout(task, new TimeSpan(0, 0, 0, 0, milliseconds), memberName, filePath, lineNumber);
23+
}
24+
25+
public static Task OrTimeout(this ValueTask task, TimeSpan timeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
26+
{
27+
return task.AsTask().TimeoutAfter(timeout, filePath, lineNumber ?? 0);
28+
}
29+
2030
public static Task OrTimeout(this Task task, int milliseconds = DefaultTimeout, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int? lineNumber = null)
2131
{
2232
return OrTimeout(task, new TimeSpan(0, 0, 0, 0, milliseconds), memberName, filePath, lineNumber);

src/SignalR/samples/ClientSample/Tcp/TcpConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public TcpConnection(EndPoint endPoint)
4343
// We claim to have inherent keep-alive so the client doesn't kill the connection when it hasn't seen ping frames.
4444
public bool HasInherentKeepAlive { get; } = true;
4545

46-
public Task DisposeAsync()
46+
public override ValueTask DisposeAsync()
4747
{
4848
Transport?.Output.Complete();
4949
Transport?.Input.Complete();
5050

5151
_socket?.Dispose();
5252

53-
return Task.CompletedTask;
53+
return default;
5454
}
5555

5656
public async Task<ConnectionContext> StartAsync()

src/SignalR/samples/ClientSample/Tcp/TcpHubConnectionBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Task<ConnectionContext> ConnectAsync(TransferFormat transferFormat, Cance
5454

5555
public Task DisposeAsync(ConnectionContext connection)
5656
{
57-
return ((TcpConnection)connection).DisposeAsync();
57+
return connection.DisposeAsync().AsTask();
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)