Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Timed Out Test isn't shown under timeout counter in Trx Report #3788

Merged
merged 1 commit into from
Sep 9, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal sealed class TrxReportGenerator :
private int _failedTestsCount;
private int _passedTestsCount;
private int _notExecutedTestsCount;
private int _timeoutTestsCount;
private bool _adapterSupportTrxCapability;

public TrxReportGenerator(
Expand Down Expand Up @@ -121,6 +122,11 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
_tests.Add(nodeChangedMessage);
_passedTestsCount++;
}
else if (nodeState is TimeoutTestNodeStateProperty)
{
_tests.Add(nodeChangedMessage);
_timeoutTestsCount++;
}
else if (Array.IndexOf(TestNodePropertiesCategories.WellKnownTestNodeTestRunOutcomeFailedProperties, nodeState.GetType()) != -1)
{
_tests.Add(nodeChangedMessage);
Expand Down Expand Up @@ -227,7 +233,7 @@ public async Task OnTestSessionFinishingAsync(SessionUid sessionUid, Cancellatio
ApplicationStateGuard.Ensure(_testStartTime is not null);

TrxReportEngine trxReportGeneratorEngine = new(_testApplicationModuleInfo, _environment, _commandLineOptionsService, _configuration,
_clock, _tests.ToArray(), _failedTestsCount, _passedTestsCount, _notExecutedTestsCount, _artifactsByExtension, _artifactsByTestNode,
_clock, _tests.ToArray(), _failedTestsCount, _passedTestsCount, _notExecutedTestsCount, _timeoutTestsCount, _artifactsByExtension, _artifactsByTestNode,
_adapterSupportTrxCapability, _testFramework, _testStartTime.Value, cancellationToken);
string reportFileName = await trxReportGeneratorEngine.GenerateReportAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public async Task OnTestHostProcessExitedAsync(ITestHostProcessInformation testH
if (!testHostProcessInformation.HasExitedGracefully)
{
TrxReportEngine trxReportGeneratorEngine = new(_testApplicationModuleInfo, _environment, _commandLineOptions, _configuration,
_clock, [], 0, 0, 0,
_clock, [], 0, 0, 0, 0,
artifacts,
new Dictionary<TestNodeUid, List<SessionFileArtifact>>(),
adapterSupportTrxCapability: null,
Expand Down Expand Up @@ -188,7 +188,7 @@ await _messageBus.PublishAsync(
if (_fileArtifacts.Count > 0)
{
TrxReportEngine trxReportGeneratorEngine = new(_testApplicationModuleInfo, _environment, _commandLineOptions, _configuration,
_clock, [], 0, 0, 0,
_clock, [], 0, 0, 0, 0,
artifacts,
new Dictionary<TestNodeUid, List<SessionFileArtifact>>(),
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal sealed partial class TrxReportEngine
private readonly int _failedTestsCount;
private readonly int _passedTestsCount;
private readonly int _notExecutedTestsCount;
private readonly int _timeoutTestsCount;
private readonly Dictionary<IExtension, List<SessionFileArtifact>> _artifactsByExtension;
private readonly Dictionary<TestNodeUid, List<SessionFileArtifact>> _artifactsByTestNode;
private readonly bool? _adapterSupportTrxCapability;
Expand All @@ -105,7 +106,7 @@ internal sealed partial class TrxReportEngine
private readonly IFileSystem _fileSystem;
private readonly bool _isCopyingFileAllowed;

public TrxReportEngine(ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, int notExecutedTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken)
public TrxReportEngine(ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, int notExecutedTestsCount, int timeoutTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken)
: this(
new SystemFileSystem(),
testApplicationModuleInfo,
Expand All @@ -117,6 +118,7 @@ public TrxReportEngine(ITestApplicationModuleInfo testApplicationModuleInfo, IEn
failedTestsCount,
passedTestsCount,
notExecutedTestsCount,
timeoutTestsCount,
artifactsByExtension,
artifactsByTestNode,
adapterSupportTrxCapability,
Expand All @@ -126,7 +128,7 @@ public TrxReportEngine(ITestApplicationModuleInfo testApplicationModuleInfo, IEn
{
}

public TrxReportEngine(IFileSystem fileSystem, ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, int notExecutedTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken, bool isCopyingFileAllowed = true)
public TrxReportEngine(IFileSystem fileSystem, ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, int notExecutedTestsCount, int timeoutTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken, bool isCopyingFileAllowed = true)
{
_testApplicationModuleInfo = testApplicationModuleInfo;
_environment = environment;
Expand All @@ -137,6 +139,7 @@ public TrxReportEngine(IFileSystem fileSystem, ITestApplicationModuleInfo testAp
_failedTestsCount = failedTestsCount;
_passedTestsCount = passedTestsCount;
_notExecutedTestsCount = notExecutedTestsCount;
_timeoutTestsCount = timeoutTestsCount;
_artifactsByExtension = artifactsByExtension;
_artifactsByTestNode = artifactsByTestNode;
_adapterSupportTrxCapability = adapterSupportTrxCapability;
Expand Down Expand Up @@ -300,7 +303,7 @@ private async Task AddResultSummaryAsync(XElement testRun, string resultSummaryO
new XAttribute("passed", _passedTestsCount),
new XAttribute("failed", _failedTestsCount),
new XAttribute("error", 0),
new XAttribute("timeout", 0),
new XAttribute("timeout", _timeoutTestsCount),
new XAttribute("aborted", 0),
new XAttribute("inconclusive", 0),
new XAttribute("passedButRunAborted", 0),
Expand Down
24 changes: 21 additions & 3 deletions test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ public async Task TrxReportEngine_GenerateReportAsyncWithNotExecutedTests_TrxExe
Assert.IsTrue(trxContent.Contains(@"notExecuted=""1"""));
}

public async Task TrxReportEngine_GenerateReportAsyncWithTimeoutTests_TrxTimeoutTestsCountHasIt()
{
// Arrange
using MemoryFileStream memoryStream = new();
PropertyBag propertyBag = new(new PassedTestNodeStateProperty());
TrxReportEngine trxReportEngine = GenerateTrxReportEngine(1, 0, propertyBag, memoryStream, timeoutTestsCount: 1);

// Act
string fileName = await trxReportEngine.GenerateReportAsync(keepReportFileStreamOpen: true);

// Assert
AssertExpectedTrxFileName(fileName);
XDocument xml = GetTrxContent(memoryStream);
AssertTrxOutcome(xml, "Completed");
string trxContent = xml.ToString();
Assert.IsTrue(trxContent.Contains(@"timeout=""1"""));
}

public async Task TrxReportEngine_GenerateReportAsync_WithArgumentTrxReportFileName_FileIsCorrectlyGenerated()
{
// Arrange
Expand Down Expand Up @@ -377,7 +395,7 @@ public async Task TrxReportEngine_GenerateReportAsync_FileAlreadyExists_WillRetr
_ = _environmentMock.SetupGet(_ => _.MachineName).Returns("MachineName");
_ = _testApplicationModuleInfoMock.Setup(_ => _.GetCurrentTestApplicationFullPath()).Returns("TestAppPath");
TrxReportEngine trxReportEngine = new(_fileSystem.Object, _testApplicationModuleInfoMock.Object, _environmentMock.Object, _commandLineOptionsMock.Object,
_configurationMock.Object, _clockMock.Object, [], 0, 0, 0,
_configurationMock.Object, _clockMock.Object, [], 0, 0, 0, 0,
_artifactsByExtension, _artifactsByTestNode, true, _testFrameworkMock.Object, DateTime.UtcNow, CancellationToken.None,
isCopyingFileAllowed: false);

Expand Down Expand Up @@ -412,7 +430,7 @@ private static void AssertExpectedTrxFileName(string fileName)
=> Assert.IsTrue(fileName.Equals("_MachineName_0001-01-01_00_00_00.000.trx", StringComparison.Ordinal));

private TrxReportEngine GenerateTrxReportEngine(int passedTestsCount, int failedTestsCount, PropertyBag propertyBag, MemoryFileStream memoryStream,
bool? adapterSupportTrxCapability = null, int notExecutedTestsCount = 0)
bool? adapterSupportTrxCapability = null, int notExecutedTestsCount = 0, int timeoutTestsCount = 0)
{
var testNode = new TestNodeUpdateMessage(
new SessionUid("1"),
Expand All @@ -432,7 +450,7 @@ private TrxReportEngine GenerateTrxReportEngine(int passedTestsCount, int failed
_ = _testApplicationModuleInfoMock.Setup(_ => _.GetCurrentTestApplicationFullPath()).Returns("TestAppPath");

return new TrxReportEngine(_fileSystem.Object, _testApplicationModuleInfoMock.Object, _environmentMock.Object, _commandLineOptionsMock.Object,
_configurationMock.Object, _clockMock.Object, testNodeUpdatedMessages, failedTestsCount, passedTestsCount, notExecutedTestsCount,
_configurationMock.Object, _clockMock.Object, testNodeUpdatedMessages, failedTestsCount, passedTestsCount, notExecutedTestsCount, timeoutTestsCount,
_artifactsByExtension, _artifactsByTestNode, adapterSupportTrxCapability, _testFrameworkMock.Object, testStartTime, cancellationToken,
isCopyingFileAllowed: false);
}
Expand Down