Skip to content

Commit

Permalink
Only print max threads when parallel test collections is on
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Nov 13, 2023
1 parent d300c88 commit 6d1bc07
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,20 @@ protected override bool Visit(ITestAssemblyExecutionStarting executionStarting)
if (executionStarting.ExecutionOptions.GetDiagnosticMessagesOrDefault())
{
var threadCount = executionStarting.ExecutionOptions.GetMaxParallelThreadsOrDefault();
var parallelTestCollections =
executionStarting.ExecutionOptions.GetDisableParallelizationOrDefault()
? "off"
: string.Format(
CultureInfo.CurrentCulture,
"on [{0} thread{1}]",
threadCount < 0 ? "unlimited" : threadCount.ToString(CultureInfo.CurrentCulture),
threadCount == 1 ? string.Empty : "s"
);

Logger.LogImportantMessage(
" Starting: {0} (parallel test collections = {1}, max threads = {2}, stop on fail = {3})",
" Starting: {0} (parallel test collections = {1}, stop on fail = {2})",
assemblyDisplayName,
!executionStarting.ExecutionOptions.GetDisableParallelizationOrDefault() ? "on" : "off",
threadCount < 0 ? "unlimited" : threadCount.ToString(CultureInfo.CurrentCulture),
parallelTestCollections,
executionStarting.ExecutionOptions.GetStopOnTestFailOrDefault() ? "on" : "off"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,20 @@ protected virtual void HandleTestAssemblyExecutionStarting(MessageHandlerArgs<IT
if (executionStarting.ExecutionOptions.GetDiagnosticMessagesOrDefault())
{
var threadCount = executionStarting.ExecutionOptions.GetMaxParallelThreadsOrDefault();
var parallelTestCollections =
executionStarting.ExecutionOptions.GetDisableParallelizationOrDefault()
? "off"
: string.Format(
CultureInfo.CurrentCulture,
"on [{0} thread{1}]",
threadCount < 0 ? "unlimited" : threadCount.ToString(CultureInfo.CurrentCulture),
threadCount == 1 ? string.Empty : "s"
);

Logger.LogImportantMessage(
" Starting: {0} (parallel test collections = {1}, max threads = {2}, stop on fail = {3})",
" Starting: {0} (parallel test collections = {1}, stop on fail = {2})",
assemblyDisplayName,
!executionStarting.ExecutionOptions.GetDisableParallelizationOrDefault() ? "on" : "off",
threadCount < 0 ? "unlimited" : threadCount.ToString(CultureInfo.CurrentCulture),
parallelTestCollections,
executionStarting.ExecutionOptions.GetStopOnTestFailOrDefault() ? "on" : "off"
);
}
Expand Down
4 changes: 2 additions & 2 deletions test/test.utility/TestDoubles/Mocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ public static ITestAssemblyExecutionFinished TestAssemblyExecutionFinished(bool
return result;
}

public static ITestAssemblyExecutionStarting TestAssemblyExecutionStarting(bool diagnosticMessages = false, string assemblyFilename = null)
public static ITestAssemblyExecutionStarting TestAssemblyExecutionStarting(bool diagnosticMessages = false, string assemblyFilename = null, bool? parallelizeTestCollections = null, int maxParallelThreads = 42, bool? stopOnFail = null)
{
var assembly = new XunitProjectAssembly { AssemblyFilename = assemblyFilename ?? "testAssembly.dll", ConfigFilename = "testAssembly.dll.config" };
var config = new TestAssemblyConfiguration { DiagnosticMessages = diagnosticMessages, MethodDisplay = Xunit.TestMethodDisplay.ClassAndMethod, MaxParallelThreads = 42, ParallelizeTestCollections = true, ShadowCopy = true, StopOnFail = true };
var config = new TestAssemblyConfiguration { DiagnosticMessages = diagnosticMessages, MethodDisplay = Xunit.TestMethodDisplay.ClassAndMethod, MaxParallelThreads = maxParallelThreads, ParallelizeTestCollections = parallelizeTestCollections, ShadowCopy = true, StopOnFail = stopOnFail };
var result = Substitute.For<ITestAssemblyExecutionStarting, InterfaceProxy<ITestAssemblyExecutionStarting>>();
result.Assembly.Returns(assembly);
result.ExecutionOptions.Returns(TestFrameworkOptions.ForExecution(config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,20 @@ public static void LogsMessage()
public class OnMessage_ITestAssemblyExecutionStarting
{
[Theory]
[InlineData(false, "[Imp] => Starting: testAssembly")]
[InlineData(true, "[Imp] => Starting: testAssembly (parallel test collections = on, max threads = 42, stop on fail = on)")]
public static void LogsMessage(bool diagnosticMessages, string expectedResult)
[InlineData(false, null, null, null, "[Imp] => Starting: testAssembly")]
[InlineData(true, false, null, null, "[Imp] => Starting: testAssembly (parallel test collections = off, stop on fail = off)")]
[InlineData(true, null, -1, null, "[Imp] => Starting: testAssembly (parallel test collections = on [unlimited threads], stop on fail = off)")]
[InlineData(true, null, 1, null, "[Imp] => Starting: testAssembly (parallel test collections = on [1 thread], stop on fail = off)")]
[InlineData(true, null, null, true, "[Imp] => Starting: testAssembly (parallel test collections = on [42 threads], stop on fail = on)")]
[InlineData(true, null, null, null, "[Imp] => Starting: testAssembly (parallel test collections = on [42 threads], stop on fail = off)")]
public static void LogsMessage(bool diagnosticMessages, bool? parallelizeTestCollections, int? maxThreads, bool? stopOnFail, string expectedResult)
{
var message = Mocks.TestAssemblyExecutionStarting(diagnosticMessages: diagnosticMessages);
var message = Mocks.TestAssemblyExecutionStarting(
diagnosticMessages: diagnosticMessages,
parallelizeTestCollections: parallelizeTestCollections,
maxParallelThreads: maxThreads ?? 42,
stopOnFail: stopOnFail
);
var handler = TestableDefaultRunnerReporterMessageHandler.Create();

handler.OnMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,20 @@ public static void LogsMessage()
public class OnMessage_ITestAssemblyExecutionStarting
{
[Theory]
[InlineData(false, "[Imp] => Starting: testAssembly")]
[InlineData(true, "[Imp] => Starting: testAssembly (parallel test collections = on, max threads = 42, stop on fail = on)")]
public static void LogsMessage(bool diagnosticMessages, string expectedResult)
[InlineData(false, null, null, null, "[Imp] => Starting: testAssembly")]
[InlineData(true, false, null, null, "[Imp] => Starting: testAssembly (parallel test collections = off, stop on fail = off)")]
[InlineData(true, null, -1, null, "[Imp] => Starting: testAssembly (parallel test collections = on [unlimited threads], stop on fail = off)")]
[InlineData(true, null, 1, null, "[Imp] => Starting: testAssembly (parallel test collections = on [1 thread], stop on fail = off)")]
[InlineData(true, null, null, true, "[Imp] => Starting: testAssembly (parallel test collections = on [42 threads], stop on fail = on)")]
[InlineData(true, null, null, null, "[Imp] => Starting: testAssembly (parallel test collections = on [42 threads], stop on fail = off)")]
public static void LogsMessage(bool diagnosticMessages, bool? parallelizeTestCollections, int? maxThreads, bool? stopOnFail, string expectedResult)
{
var message = Mocks.TestAssemblyExecutionStarting(diagnosticMessages: diagnosticMessages);
var message = Mocks.TestAssemblyExecutionStarting(
diagnosticMessages: diagnosticMessages,
parallelizeTestCollections: parallelizeTestCollections,
maxParallelThreads: maxThreads ?? 42,
stopOnFail: stopOnFail
);
var handler = TestableDefaultRunnerReporterWithTypesMessageHandler.Create();

handler.OnMessageWithTypes(message, null);
Expand Down

0 comments on commit 6d1bc07

Please sign in to comment.