test(headless): cover K4 death and cancellation
This commit is contained in:
parent
97c174fbb2
commit
bd236ce553
2 changed files with 115 additions and 17 deletions
|
|
@ -358,6 +358,76 @@ public sealed class HeadlessProcessSchedulerTests
|
|||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ThirtySessionsConvergeAcrossRandomizedCancellationEdges()
|
||||
{
|
||||
const int sessionCount = 30;
|
||||
var random = new Random(0xAC2013);
|
||||
for (int iteration = 0; iteration < 5; iteration++)
|
||||
{
|
||||
var configuration = new HeadlessConfiguration
|
||||
{
|
||||
Version = 1,
|
||||
Sessions = Enumerable.Range(0, sessionCount)
|
||||
.Select(index => Descriptor(
|
||||
$"cancel-{iteration}-{index}",
|
||||
$"cancel-{iteration}-{index}-stdin"))
|
||||
.Cast<HeadlessSessionDescriptor?>()
|
||||
.ToList(),
|
||||
};
|
||||
var operations = new FixtureSessionOperations();
|
||||
using var diagnostics = new StringWriter();
|
||||
using var host = new HeadlessProcessHost(
|
||||
configuration,
|
||||
HeadlessPathSet.Resolve(
|
||||
new HeadlessPathOverrides()),
|
||||
new System.IO.StringReader(string.Concat(
|
||||
Enumerable.Repeat(
|
||||
"random-cancel-password"
|
||||
+ Environment.NewLine,
|
||||
sessionCount))),
|
||||
diagnostics,
|
||||
operations);
|
||||
using var cancellation = new CancellationTokenSource(
|
||||
TimeSpan.FromMilliseconds(random.Next(37, 144)));
|
||||
|
||||
HeadlessExitCode result =
|
||||
await host.RunAsync(cancellation.Token);
|
||||
|
||||
Assert.True(cancellation.IsCancellationRequested);
|
||||
Assert.Equal(HeadlessExitCode.Success, result);
|
||||
Assert.Equal(sessionCount, operations.CreatedSessionCount);
|
||||
Assert.All(
|
||||
host.Sessions,
|
||||
static session =>
|
||||
Assert.False(session.IsFaulted));
|
||||
|
||||
host.Dispose();
|
||||
|
||||
Assert.Equal(sessionCount, operations.DisposedSessionCount);
|
||||
Assert.All(
|
||||
host.Sessions,
|
||||
static session =>
|
||||
Assert.True(
|
||||
session.Runtime
|
||||
.CaptureOwnership()
|
||||
.IsConverged));
|
||||
string output = diagnostics.ToString();
|
||||
Assert.Contains(
|
||||
"\"state\":\"disposed\"",
|
||||
output,
|
||||
StringComparison.Ordinal);
|
||||
Assert.Contains(
|
||||
$"\"convergedRuntimeCount\":{sessionCount}",
|
||||
output,
|
||||
StringComparison.Ordinal);
|
||||
Assert.DoesNotContain(
|
||||
"random-cancel-password",
|
||||
output,
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowingPolicyQuarantinesOnlyItsOwnSession()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue