Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Halter <halter73@gmail.com>2022-01-22 07:09:02 +0300
committerStephen Halter <halter73@gmail.com>2022-01-22 07:51:47 +0300
commit08c90d9e8b68d248aab348c29e81b1f871fbec44 (patch)
treee4e7fe2ac734770aaa55f1df203f847eb0779442
parent149f6d94f64ae61928e74eb59307237bcc149271 (diff)
-rw-r--r--src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs
index 3d7a5b7652..9b4ca06859 100644
--- a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs
+++ b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs
@@ -67,7 +67,7 @@ public class HubConnectionTests : FunctionalTestBase
return hubConnectionBuilder.Build();
}
- private Func<EndPoint, ValueTask<ConnectionContext>> GetHttpConnectionFactory(string url, ILoggerFactory loggerFactory, string path, HttpTransportType transportType, TransferFormat transferFormat)
+ private static Func<EndPoint, ValueTask<ConnectionContext>> GetHttpConnectionFactory(string url, ILoggerFactory loggerFactory, string path, HttpTransportType transportType, TransferFormat transferFormat)
{
return async endPoint =>
{
@@ -75,7 +75,8 @@ public class HubConnectionTests : FunctionalTestBase
var options = new HttpConnectionOptions { Url = httpEndpoint.Uri, Transports = transportType, DefaultTransferFormat = transferFormat };
var connection = new HttpConnection(options, loggerFactory);
- await connection.StartAsync();
+ // This is used by CanBlockOnAsyncOperationsWithOneAtATimeSynchronizationContext, so the ConfigureAwait(false) is important.
+ await connection.StartAsync().ConfigureAwait(false);
return connection;
};
@@ -2105,6 +2106,9 @@ public class HubConnectionTests : FunctionalTestBase
try
{
+ // Yield first so the rest of the test runs in the OneAtATimeSynchronizationContext.Run loop
+ await Task.Yield();
+
Assert.True(connection.StartAsync().Wait(DefaultTimeout));
var invokeTask = connection.InvokeAsync<string>(nameof(TestHub.HelloWorld));
@@ -2126,20 +2130,31 @@ public class HubConnectionTests : FunctionalTestBase
private class OneAtATimeSynchronizationContext : SynchronizationContext, IDisposable
{
- private Channel<(SendOrPostCallback, object)> _taskQueue = Channel.CreateUnbounded<(SendOrPostCallback, object)>();
+ private readonly Channel<(SendOrPostCallback, object)> _taskQueue = Channel.CreateUnbounded<(SendOrPostCallback, object)>();
+ private bool _disposed;
public OneAtATimeSynchronizationContext()
{
- _ = Run();
+ // Task.Run to avoid running with xUnit's AsyncTestSyncContext as well
+ _ = Task.Run(Run);
}
public override void Post(SendOrPostCallback d, object state)
{
+ if (_disposed)
+ {
+ // There should be no other calls to Post() after dispose. If there are calls,
+ // the test has most likely failed with a timeout. Let the callbacks run so the
+ // timeout exception gets reported accurately instead of as a long-running test.
+ d(state);
+ }
+
_taskQueue.Writer.TryWrite((d, state));
}
public void Dispose()
{
+ _disposed = true;
_taskQueue.Writer.Complete();
}
@@ -2158,7 +2173,6 @@ public class HubConnectionTests : FunctionalTestBase
}
}
-
private class PollTrackingMessageHandler : DelegatingHandler
{
public Task<HttpResponseMessage> ActivePoll { get; private set; }