Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 6 additions & 7 deletions src/ModularPipelines/Helpers/SpectreResultsPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,10 @@ private static Table CreateModulesTableCore(PipelineSummary pipelineSummary)
table.AddColumn(new TableColumn("[bold]Status[/]").Centered());
table.AddColumn(new TableColumn("[bold]Duration[/]").RightAligned());
var reportLookup = pipelineSummary.RunReport is null
? new Dictionary<Type, ModuleRunReport>()
: pipelineSummary.Modules
.Zip(pipelineSummary.RunReport.Modules)
.GroupBy(static pair => pair.First.GetType())
.ToDictionary(static group => group.Key, static group => group.First().Second);
? new Dictionary<string, ModuleRunReport>(StringComparer.Ordinal)
: pipelineSummary.RunReport.Modules
.GroupBy(static report => report.ModuleTypeName, StringComparer.Ordinal)
.ToDictionary(static group => group.Key, static group => group.First(), StringComparer.Ordinal);
var showDeltas = pipelineSummary.RunReport?.TotalDurationDelta.HasValue == true
|| reportLookup.Values.Any(static module => module.DurationDelta.HasValue);
if (showDeltas)
Expand Down Expand Up @@ -208,7 +207,7 @@ private static void AddModuleRow(
Table table,
object module,
Dictionary<string, ModuleTimeline> timelineLookup,
IReadOnlyDictionary<Type, ModuleRunReport> reportLookup,
IReadOnlyDictionary<string, ModuleRunReport> reportLookup,
bool showDeltas)
{
var moduleName = module.GetType().Name;
Expand Down Expand Up @@ -249,7 +248,7 @@ private static void AddModuleRow(
};
if (showDeltas)
{
cells.Add(reportLookup.TryGetValue(module.GetType(), out var report)
cells.Add(reportLookup.TryGetValue(ModuleTypeIdentifier.Get(module.GetType()), out var report)
? FormatDelta(report.DurationDelta)
: "[dim]-[/]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ protected internal override Task<bool> ExecuteAsync(
CancellationToken cancellationToken) => Task.FromResult(true);
}

private sealed class FirstModule : SkippedModule
{
}

private sealed class SecondModule : SkippedModule
{
}

[Test]
public async Task ModulesTable_IsCompactWithoutBlankSeparator_AndLabelsSkippedModules()
{
Expand Down Expand Up @@ -145,6 +153,51 @@ public async Task ModulesTable_ShowsTotalDeltaWithoutMatchingModuleDeltas()
}
}

[Test]
public async Task ModulesTable_MatchesDurationDeltasByModuleType()
{
var start = new DateTimeOffset(2026, 7, 27, 12, 0, 0, TimeSpan.Zero);
var firstModule = new FirstModule();
var secondModule = new SecondModule();
var summary = new PipelineSummary(
[firstModule, secondModule],
[],
TimeSpan.FromSeconds(5),
start,
start.AddSeconds(5)) with
{
RunReport = new PipelineRunReport
{
Modules =
[
new ModuleRunReport
{
ModuleName = nameof(SecondModule),
ModuleTypeName = ModuleTypeIdentifier.Get(typeof(SecondModule)),
DurationDelta = TimeSpan.FromSeconds(2),
},
new ModuleRunReport
{
ModuleName = nameof(FirstModule),
ModuleTypeName = ModuleTypeIdentifier.Get(typeof(FirstModule)),
DurationDelta = TimeSpan.FromSeconds(1),
},
],
},
};

var output = RenderToString(SpectreResultsPrinter.CreateModulesTable(summary));
var lines = output.Split(Environment.NewLine);
var firstModuleLine = lines.Single(line => line.Contains(nameof(FirstModule), StringComparison.Ordinal));
var secondModuleLine = lines.Single(line => line.Contains(nameof(SecondModule), StringComparison.Ordinal));

using (Assert.Multiple())
{
await Assert.That(firstModuleLine).Contains("+1s");
await Assert.That(secondModuleLine).Contains("+2s");
}
}

private static string RenderToString(IRenderable renderable)
{
using var writer = new StringWriter();
Expand Down
Loading