Skip to content

Commit

Permalink
Use test display name instead of UID for slowest tests (#4377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Dec 18, 2024
1 parent d2ab2f9 commit 18e39e9
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Testing.TestInfrastructure;

public sealed class SlowestTestsConsumer : IDataConsumer, ITestSessionLifetimeHandler
{
private readonly List<(string TestId, double Milliseconds)> _testPerf = [];
private readonly List<(string TestId, string DisplayName, double Milliseconds)> _testPerf = [];

public Type[] DataTypesConsumed => [typeof(TestNodeUpdateMessage)];

Expand All @@ -32,17 +32,17 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
}

double milliseconds = testNodeUpdatedMessage.TestNode.Properties.Single<TimingProperty>().GlobalTiming.Duration.TotalMilliseconds;
_testPerf.Add((testNodeUpdatedMessage.TestNode.Uid, milliseconds));
_testPerf.Add((testNodeUpdatedMessage.TestNode.Uid, testNodeUpdatedMessage.TestNode.DisplayName, milliseconds));

return Task.CompletedTask;
}

public Task OnTestSessionFinishingAsync(SessionUid sessionUid, CancellationToken cancellationToken)
{
Console.WriteLine("Slowest 10 tests");
foreach ((string testId, double milliseconds) in _testPerf.OrderByDescending(x => x.Milliseconds).Take(10))
foreach ((_, string displayName, double milliseconds) in _testPerf.OrderByDescending(x => x.Milliseconds).Take(10))
{
Console.WriteLine($"{testId} {TimeSpan.FromMilliseconds(milliseconds).TotalSeconds:F5}s");
Console.WriteLine($"{displayName} {TimeSpan.FromMilliseconds(milliseconds).TotalSeconds:F5}s");
}

return Task.CompletedTask;
Expand Down

0 comments on commit 18e39e9

Please sign in to comment.