Fix flaky dispatcher test
This commit is contained in:
parent
a9dca60a10
commit
0f1bc0e0bd
|
|
@ -383,6 +383,8 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
ServerLogger.Log("End writing response.");
|
ServerLogger.Log("End writing response.");
|
||||||
|
|
||||||
reason = ConnectionResult.Reason.CompilationCompleted;
|
reason = ConnectionResult.Reason.CompilationCompleted;
|
||||||
|
|
||||||
|
_eventBus.CompilationCompleted();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,13 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
public virtual void ConnectionCompleted(int count)
|
public virtual void ConnectionCompleted(int count)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when a compilation is completed successfully and the response is written to the stream.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void CompilationCompleted()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when a bad client connection was detected and the server will be shutting down as a
|
/// Called when a bad client connection was detected and the server will be shutting down as a
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -335,7 +336,7 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ensure server respects keep alive and shuts down after processing simultaneous connections.
|
/// Ensure server respects keep alive and shuts down after processing simultaneous connections.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact(Skip = "https://github.com/aspnet/Razor/issues/2018")]
|
[Fact]
|
||||||
public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout()
|
public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -352,6 +353,7 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
var source = new TaskCompletionSource<bool>();
|
var source = new TaskCompletionSource<bool>();
|
||||||
var connectionTask = CreateConnectionWithEmptyServerRequest(c =>
|
var connectionTask = CreateConnectionWithEmptyServerRequest(c =>
|
||||||
{
|
{
|
||||||
|
// Keep the connection active until we decide to end it.
|
||||||
c.WaitForDisconnectAsyncFunc = _ => source.Task;
|
c.WaitForDisconnectAsyncFunc = _ => source.Task;
|
||||||
});
|
});
|
||||||
list.Add(source);
|
list.Add(source);
|
||||||
|
|
@ -370,24 +372,42 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
var keepAlive = TimeSpan.FromSeconds(1);
|
|
||||||
var eventBus = new TestableEventBus();
|
var eventBus = new TestableEventBus();
|
||||||
|
var completedCompilations = 0;
|
||||||
|
var allCompilationsComplete = new TaskCompletionSource<bool>();
|
||||||
|
eventBus.CompilationComplete += (obj, args) =>
|
||||||
|
{
|
||||||
|
if (++completedCompilations == totalCount)
|
||||||
|
{
|
||||||
|
// All compilations have completed.
|
||||||
|
allCompilationsComplete.SetResult(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var keepAlive = TimeSpan.FromSeconds(1);
|
||||||
var dispatcherTask = Task.Run(() =>
|
var dispatcherTask = Task.Run(() =>
|
||||||
{
|
{
|
||||||
var dispatcher = new DefaultRequestDispatcher(connectionHost.Object, compilerHost, CancellationToken.None, eventBus, keepAlive);
|
var dispatcher = new DefaultRequestDispatcher(connectionHost.Object, compilerHost, CancellationToken.None, eventBus, keepAlive);
|
||||||
dispatcher.Run();
|
dispatcher.Run();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Wait for all connections to be created.
|
||||||
await readySource.Task;
|
await readySource.Task;
|
||||||
|
|
||||||
|
// Wait for all compilations to complete.
|
||||||
|
await allCompilationsComplete.Task;
|
||||||
|
|
||||||
|
// Now allow all the connections to be disconnected.
|
||||||
foreach (var source in list)
|
foreach (var source in list)
|
||||||
{
|
{
|
||||||
source.SetResult(true);
|
source.SetResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
// Now dispatcher should be in an idle state with no active connections.
|
||||||
await dispatcherTask;
|
await dispatcherTask;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
Assert.False(eventBus.HasDetectedBadConnection);
|
||||||
Assert.Equal(totalCount, eventBus.CompletedCount);
|
Assert.Equal(totalCount, eventBus.CompletedCount);
|
||||||
Assert.True(eventBus.LastProcessedTime.HasValue, "LastProcessedTime should have had a value.");
|
Assert.True(eventBus.LastProcessedTime.HasValue, "LastProcessedTime should have had a value.");
|
||||||
Assert.True(eventBus.HitKeepAliveTimeout, "HitKeepAliveTimeout should have been hit.");
|
Assert.True(eventBus.HitKeepAliveTimeout, "HitKeepAliveTimeout should have been hit.");
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,27 @@
|
||||||
// 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;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Tools
|
namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
{
|
{
|
||||||
internal class TestableEventBus : EventBus
|
internal class TestableEventBus : EventBus
|
||||||
{
|
{
|
||||||
public int ListeningCount;
|
|
||||||
public int ConnectionCount;
|
|
||||||
public int CompletedCount;
|
|
||||||
public DateTime? LastProcessedTime;
|
|
||||||
public TimeSpan? KeepAlive;
|
|
||||||
public bool HasDetectedBadConnection;
|
|
||||||
public bool HitKeepAliveTimeout;
|
|
||||||
public event EventHandler Listening;
|
public event EventHandler Listening;
|
||||||
|
public event EventHandler CompilationComplete;
|
||||||
|
|
||||||
|
public int ListeningCount { get; private set; }
|
||||||
|
|
||||||
|
public int ConnectionCount { get; private set; }
|
||||||
|
|
||||||
|
public int CompletedCount { get; private set; }
|
||||||
|
|
||||||
|
public DateTime? LastProcessedTime { get; private set; }
|
||||||
|
|
||||||
|
public TimeSpan? KeepAlive { get; private set; }
|
||||||
|
|
||||||
|
public bool HasDetectedBadConnection { get; private set; }
|
||||||
|
|
||||||
|
public bool HitKeepAliveTimeout { get; private set; }
|
||||||
|
|
||||||
public override void ConnectionListening()
|
public override void ConnectionListening()
|
||||||
{
|
{
|
||||||
|
|
@ -35,6 +41,11 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
LastProcessedTime = DateTime.Now;
|
LastProcessedTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void CompilationCompleted()
|
||||||
|
{
|
||||||
|
CompilationComplete?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
public override void UpdateKeepAlive(TimeSpan timeSpan)
|
public override void UpdateKeepAlive(TimeSpan timeSpan)
|
||||||
{
|
{
|
||||||
KeepAlive = timeSpan;
|
KeepAlive = timeSpan;
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,8 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
/// A shutdown request should not abort an existing compilation. It should be allowed to run to
|
/// A shutdown request should not abort an existing compilation. It should be allowed to run to
|
||||||
/// completion.
|
/// completion.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ConditionalFact(Skip = "Skipping temporarily on non-windows. https://github.com/aspnet/Razor/issues/1991")]
|
// Skipping temporarily on non-windows. https://github.com/aspnet/Razor/issues/1991
|
||||||
|
[ConditionalFact]
|
||||||
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
public async Task ServerRunning_ShutdownRequest_DoesNotAbortCompilation()
|
public async Task ServerRunning_ShutdownRequest_DoesNotAbortCompilation()
|
||||||
{
|
{
|
||||||
|
|
@ -153,7 +154,8 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Multiple clients should be able to send shutdown requests to the server.
|
/// Multiple clients should be able to send shutdown requests to the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ConditionalFact(Skip = "Skipping temporarily on non-windows. https://github.com/aspnet/Razor/issues/1991")]
|
// Skipping temporarily on non-windows. https://github.com/aspnet/Razor/issues/1991
|
||||||
|
[ConditionalFact]
|
||||||
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
public async Task ServerRunning_MultipleShutdownRequests_HandlesSuccessfully()
|
public async Task ServerRunning_MultipleShutdownRequests_HandlesSuccessfully()
|
||||||
{
|
{
|
||||||
|
|
@ -191,7 +193,8 @@ namespace Microsoft.AspNetCore.Razor.Tools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalFact(Skip = "Skipping temporarily on non-windows. https://github.com/aspnet/Razor/issues/1991")]
|
// Skipping temporarily on non-windows. https://github.com/aspnet/Razor/issues/1991
|
||||||
|
[ConditionalFact]
|
||||||
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
public async Task ServerRunning_CancelCompilation_CancelsSuccessfully()
|
public async Task ServerRunning_CancelCompilation_CancelsSuccessfully()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue