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 duration in console logger for parallel tests #2739

Merged
2 commits merged into from
Feb 8, 2021
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
6 changes: 4 additions & 2 deletions src/vstest.console/Internal/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,11 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
var source = sd.Key;
var sourceSummary = new SourceSummary();

foreach (var result in sd.ToArray())
var results = sd.ToArray();
// duration of the whole source is the difference between the test that ended last and the one that started first
sourceSummary.Duration = !results.Any() ? TimeSpan.Zero : results.Max(r => r.EndTime) - results.Min(r => r.StartTime);
Sanan07 marked this conversation as resolved.
Show resolved Hide resolved
foreach (var result in results)
{
sourceSummary.Duration += result.Duration;
switch (result.Outcome)
{
case TestOutcome.Passed:
Expand Down
45 changes: 27 additions & 18 deletions test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,28 +612,28 @@ public void TestResultHandlerShouldShowFailedTestsAndPassedTestsForQuietVebosity
loggerEvents.RaiseTestRunComplete(new TestRunCompleteEventArgs(new Mock<ITestRunStatistics>().Object, false, false, null, new Collection<AttachmentSet>(), TimeSpan.FromSeconds(1)));
loggerEvents.WaitForEventCompletion();

this.mockOutput.Verify(o => o.Write(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary,
this.mockOutput.Verify(o => o.Write(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary,
(CommandLineResources.PassedTestIndicator + "!").PadRight(8),
0.ToString().PadLeft(5),
1.ToString().PadLeft(5),
0.ToString().PadLeft(5),
1.ToString().PadLeft(5),
1.ToString().PadLeft(5), 2
.ToString().PadLeft(5),
.ToString().PadLeft(5),
"1 m 2 s"), OutputLevel.Information), Times.Once);

this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework,
"TestSourcePassed",
expectedFramework), OutputLevel.Information), Times.Once);
this.mockOutput.Verify(o => o.Write(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary,
this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework,
"TestSourcePassed",
expectedFramework), OutputLevel.Information), Times.Once);

this.mockOutput.Verify(o => o.Write(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary,
(CommandLineResources.FailedTestIndicator + "!").PadRight(8),
1.ToString().PadLeft(5),
1.ToString().PadLeft(5),
1.ToString().PadLeft(5),
3.ToString().PadLeft(5),
"1 h 6 m"), OutputLevel.Information), Times.Once);
3.ToString().PadLeft(5),
"1 h 2 m"), OutputLevel.Information), Times.Once);

this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework,
"TestSource",
this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework,
"TestSource",
expectedFramework), OutputLevel.Information), Times.Once);
}

Expand Down Expand Up @@ -1171,12 +1171,12 @@ public void ResultsInHeirarchichalOrderShouldReportCorrectCount()
Guid parentExecutionId = Guid.NewGuid();
TestProperty ParentExecIdProperty = TestProperty.Register("ParentExecId", "ParentExecId", typeof(Guid), TestPropertyAttributes.Hidden, typeof(ObjectModel.TestResult));
TestProperty ExecutionIdProperty = TestProperty.Register("ExecutionId", "ExecutionId", typeof(Guid), TestPropertyAttributes.Hidden, typeof(ObjectModel.TestResult));
TestProperty TestTypeProperty = TestProperty.Register("TestType", "TestType" , typeof(Guid), TestPropertyAttributes.Hidden, typeof(ObjectModel.TestResult));
TestProperty TestTypeProperty = TestProperty.Register("TestType", "TestType", typeof(Guid), TestPropertyAttributes.Hidden, typeof(ObjectModel.TestResult));

var result1 = new ObjectModel.TestResult(testCase1) { Outcome = TestOutcome.Failed };
result1.SetPropertyValue(ExecutionIdProperty, parentExecutionId);

var result2 = new ObjectModel.TestResult(testCase2) { Outcome = TestOutcome.Passed};
var result2 = new ObjectModel.TestResult(testCase2) { Outcome = TestOutcome.Passed };
result2.SetPropertyValue(ExecutionIdProperty, Guid.NewGuid());
result2.SetPropertyValue(ParentExecIdProperty, parentExecutionId);

Expand Down Expand Up @@ -1218,16 +1218,22 @@ private void Setup()
DisplayName = "TestName"
};

var duration = new TimeSpan(1, 2, 3);
var testresult = new ObjectModel.TestResult(testcase)
{
Outcome = TestOutcome.Passed,
Duration = new TimeSpan(1, 2, 3)
Duration = duration,
StartTime = DateTime.Now - duration,
EndTime = DateTime.Now
};

var duration1 = new TimeSpan(0, 0, 4, 5, 60);
var testresult1 = new ObjectModel.TestResult(testcase)
{
Outcome = TestOutcome.Failed,
Duration = new TimeSpan(0, 0, 4, 5, 60)
Duration = duration1,
StartTime = DateTime.Now - duration1,
EndTime = DateTime.Now
};

var testresult2 = new ObjectModel.TestResult(testcase)
Expand Down Expand Up @@ -1257,10 +1263,13 @@ private void Setup()
DisplayName = "TestName"
};

var duration = new TimeSpan(0, 0, 1, 2, 3);
var testresult = new ObjectModel.TestResult(testcase)
{
Outcome = TestOutcome.Passed,
Duration = new TimeSpan(0, 0, 1, 2, 3)
Duration = duration,
StartTime = DateTime.Now - duration,
EndTime = DateTime.Now
};

var testresult1 = new ObjectModel.TestResult(testcase)
Expand Down