Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout
{
// Arrange
var totalCount = 2;
var readySource = new TaskCompletionSource<bool>();
var timeout = TimeSpan.FromMinutes(1);
var readySource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var list = new List<TaskCompletionSource<bool>>();
var connectionHost = new Mock<ConnectionHost>();
connectionHost
Expand All @@ -349,7 +350,7 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout
{
if (list.Count < totalCount)
{
var source = new TaskCompletionSource<bool>();
var source = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var connectionTask = CreateConnectionWithEmptyServerRequest(c =>
{
// Keep the connection active until we decide to end it.
Expand All @@ -373,10 +374,10 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout

var eventBus = new TestableEventBus();
var completedCompilations = 0;
var allCompilationsComplete = new TaskCompletionSource<bool>();
var allCompilationsComplete = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
eventBus.CompilationComplete += (obj, args) =>
{
if (++completedCompilations == totalCount)
if (Interlocked.Increment(ref completedCompilations) == totalCount)
{
// All compilations have completed.
allCompilationsComplete.SetResult(true);
Expand All @@ -391,10 +392,10 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout
}, TestContext.CancellationToken);

// Wait for all connections to be created.
await readySource.Task;
await readySource.Task.WaitAsync(timeout, TestContext.CancellationToken);

// Wait for all compilations to complete.
await allCompilationsComplete.Task;
await allCompilationsComplete.Task.WaitAsync(timeout, TestContext.CancellationToken);

// Now allow all the connections to be disconnected.
foreach (var source in list)
Expand All @@ -404,7 +405,7 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout

// Act
// Now dispatcher should be in an idle state with no active connections.
await dispatcherTask;
await dispatcherTask.WaitAsync(timeout, TestContext.CancellationToken);

// Assert
Assert.IsFalse(eventBus.HasDetectedBadConnection);
Expand Down
Loading