Skip to content

Commit f76e203

Browse files
authored
Update host test command execution logging: include PID on exit, remove confusing OK/FAIL, add caller name (#116658)
When launching a process to test, host tests write to the console on launch, wait for exit, and exit. Currently, they also log OK/FAIL based on the exit code and a parameter for whether failure is expected. All tests already do their own validation for if the command should pass/fail - having this extra logging is not useful and can be actively confusing, since it relies on tests also passing in that parameter (even though that is not used for actual validation/asserts). Update the logging to remove the OK/FAIL, include the PID on exit, and add the caller name (for test identification).
1 parent 1bd56d4 commit f76e203

25 files changed

+172
-130
lines changed

src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void FrameworkDependent_GUI_DownlevelHostFxr_ErrorDialog()
172172
command.Process.Kill();
173173

174174
command
175-
.WaitForExit(true)
175+
.WaitForExit()
176176
.Should().Fail()
177177
.And.HaveStdErrContaining("Bundle header version compatibility check failed.")
178178
.And.HaveStdErrContaining($"Showing error dialog for application: '{Path.GetFileName(singleFile)}' - error code: 0x{expectedErrorCode}")

src/installer/tests/AppHost.Bundle.Tests/BundleRename.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public BundleRename(SharedTestState fixture)
2323
[Theory]
2424
[ActiveIssue("https://github.com/dotnet/runtime/issues/38013")]
2525
[InlineData(true)] // Test renaming the single-exe when contents are extracted
26-
[InlineData(false)] // Test renaming the single-exe when contents are not extracted
26+
[InlineData(false)] // Test renaming the single-exe when contents are not extracted
2727
private void Bundle_can_be_renamed_while_running(bool testExtraction)
2828
{
2929
string singleFile = sharedTestState.App.Bundle(testExtraction ? BundleOptions.BundleAllContent : BundleOptions.None);
@@ -51,7 +51,7 @@ private void Bundle_can_be_renamed_while_running(bool testExtraction)
5151
File.Move(singleFile, renameFile);
5252
File.Create(resumeFile).Close();
5353

54-
singleExe.WaitForExit(expectedToFail: false, twoMinutes)
54+
singleExe.WaitForExit(twoMinutes)
5555
.Should().Pass()
5656
.And.HaveStdOutContaining("Hello World!");
5757
}

src/installer/tests/HostActivation.Tests/DependencyResolution/ComponentSharedTestStateBase.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.DotNet.Cli.Build.Framework;
66
using System;
77
using System.IO;
8+
using System.Runtime.CompilerServices;
89

910
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
1011
{
@@ -44,12 +45,12 @@ protected virtual void CustomizeDotNetWithNetCoreApp(DotNetBuilder builder)
4445
{
4546
}
4647

47-
public CommandResult RunComponentResolutionTest(TestApp component, Action<Command> commandCustomizer = null)
48+
public CommandResult RunComponentResolutionTest(TestApp component, Action<Command> commandCustomizer = null, [CallerMemberName] string caller = "")
4849
{
49-
return RunComponentResolutionTest(component.AppDll, FrameworkReferenceApp, DotNetWithNetCoreApp.GreatestVersionHostFxrPath, commandCustomizer);
50+
return RunComponentResolutionTest(component.AppDll, FrameworkReferenceApp, DotNetWithNetCoreApp.GreatestVersionHostFxrPath, commandCustomizer, caller);
5051
}
5152

52-
public CommandResult RunComponentResolutionTest(string componentPath, TestApp hostApp, string hostFxrFolder, Action<Command> commandCustomizer = null)
53+
public CommandResult RunComponentResolutionTest(string componentPath, TestApp hostApp, string hostFxrFolder, Action<Command> commandCustomizer = null, [CallerMemberName] string caller = "")
5354
{
5455
string[] args =
5556
{
@@ -65,16 +66,16 @@ public CommandResult RunComponentResolutionTest(string componentPath, TestApp ho
6566
.MultilevelLookup(false);
6667
commandCustomizer?.Invoke(command);
6768

68-
return command.Execute()
69+
return command.Execute(caller)
6970
.StdErrAfter("corehost_resolve_component_dependencies = {");
7071
}
7172

72-
public CommandResult RunComponentResolutionMultiThreadedTest(TestApp componentOne, TestApp componentTwo)
73+
public CommandResult RunComponentResolutionMultiThreadedTest(TestApp componentOne, TestApp componentTwo, [CallerMemberName] string caller = "")
7374
{
74-
return RunComponentResolutionMultiThreadedTest(componentOne.AppDll, componentTwo.AppDll, FrameworkReferenceApp, DotNetWithNetCoreApp.GreatestVersionHostFxrPath);
75+
return RunComponentResolutionMultiThreadedTest(componentOne.AppDll, componentTwo.AppDll, FrameworkReferenceApp, DotNetWithNetCoreApp.GreatestVersionHostFxrPath, caller);
7576
}
7677

77-
public CommandResult RunComponentResolutionMultiThreadedTest(string componentOnePath, string componentTwoPath, TestApp hostApp, string hostFxrFolder)
78+
public CommandResult RunComponentResolutionMultiThreadedTest(string componentOnePath, string componentTwoPath, TestApp hostApp, string hostFxrFolder, [CallerMemberName] string caller = "")
7879
{
7980
string[] args =
8081
{
@@ -89,7 +90,7 @@ public CommandResult RunComponentResolutionMultiThreadedTest(string componentOne
8990
return Command.Create(NativeHostPath, args)
9091
.EnableTracingAndCaptureOutputs()
9192
.MultilevelLookup(false)
92-
.Execute();
93+
.Execute(caller);
9394
}
9495

9596
protected override void Dispose(bool disposing)

src/installer/tests/HostActivation.Tests/DependencyResolution/DepsFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public void DepsJsonWithUtf8Bom()
5353
{
5454
// Test that .deps.json files with UTF8 BOM are parsed correctly
5555
TestApp app = sharedState.FrameworkReferenceApp;
56-
56+
5757
// Create a copy of the existing deps.json with UTF8 BOM
58-
string depsJsonWithBom = Path.Combine(Path.GetDirectoryName(sharedState.DepsJsonPath),
58+
string depsJsonWithBom = Path.Combine(Path.GetDirectoryName(sharedState.DepsJsonPath),
5959
Path.GetFileNameWithoutExtension(sharedState.DepsJsonPath) + "_bom.deps.json");
60-
60+
6161
try
6262
{
6363
// Read the original deps.json content and write with UTF8 BOM

src/installer/tests/HostActivation.Tests/DependencyResolution/PerAssemblyVersionResolution.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Runtime.CompilerServices;
67
using Xunit;
78

89
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
@@ -59,7 +60,7 @@ public void AppWithSameAssemblyAsFramework(string testAssemblyName, string appAs
5960
RunTest(testAssemblyName, appAsmVersion, appFileVersion, appWins);
6061
}
6162

62-
protected abstract void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins);
63+
protected abstract void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins, [CallerMemberName] string caller = "");
6364

6465
public class SharedTestState : ComponentSharedTestStateBase
6566
{
@@ -99,7 +100,7 @@ public AppPerAssemblyVersionResolution(SharedTestState sharedState)
99100
{
100101
}
101102

102-
protected override void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins)
103+
protected override void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins, [CallerMemberName] string caller = "")
103104
{
104105
var app = SharedState.CreateTestFrameworkReferenceApp(b => b
105106
.WithPackage(TestVersionsPackage, "1.0.0", lib => lib
@@ -112,7 +113,7 @@ protected override void RunTest(string testAssemblyName, string appAsmVersion, s
112113

113114
SharedState.DotNetWithNetCoreApp.Exec(app.AppDll)
114115
.EnableTracingAndCaptureOutputs()
115-
.Execute()
116+
.Execute(caller)
116117
.Should().Pass()
117118
.And.HaveResolvedAssembly(expectedTestAssemblyPath)
118119
.And.HaveUsedFrameworkProbe(SharedState.DotNetWithNetCoreApp.GreatestVersionSharedFxPath, level: 1);
@@ -128,7 +129,7 @@ public AdditionalDepsPerAssemblyVersionResolution(SharedTestState sharedState)
128129
{
129130
}
130131

131-
protected override void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins)
132+
protected override void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins, [CallerMemberName] string caller = "")
132133
{
133134
using (TestApp additionalDependency = TestApp.CreateEmpty("additionalDeps"))
134135
{
@@ -151,7 +152,7 @@ protected override void RunTest(string testAssemblyName, string appAsmVersion, s
151152
: Path.Combine(SharedState.DotNetWithNetCoreApp.GreatestVersionSharedFxPath, $"{testAssemblyName}.dll");
152153
SharedState.DotNetWithNetCoreApp.Exec(Constants.AdditionalDeps.CommandLineArgument, additionalDependency.DepsJson, app.AppDll)
153154
.EnableTracingAndCaptureOutputs()
154-
.Execute()
155+
.Execute(caller)
155156
.Should().Pass()
156157
.And.HaveUsedAdditionalDeps(additionalDependency.DepsJson)
157158
.And.HaveResolvedAssembly(expectedTestAssemblyPath)
@@ -169,7 +170,7 @@ public ComponentPerAssemblyVersionResolution(SharedTestState sharedState)
169170
{
170171
}
171172

172-
protected override void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins)
173+
protected override void RunTest(string testAssemblyName, string appAsmVersion, string appFileVersion, bool appWins, [CallerMemberName] string caller = "")
173174
{
174175
var component = SharedState.CreateComponentWithNoDependencies(b => b
175176
.WithPackage(TestVersionsPackage, "1.0.0", lib => lib
@@ -180,7 +181,7 @@ protected override void RunTest(string testAssemblyName, string appAsmVersion, s
180181
// For component dependency resolution, frameworks are not considered, so the assembly from the component always wins
181182
string expectedTestAssemblyPath = Path.Combine(component.Location, testAssemblyName + ".dll");
182183

183-
SharedState.RunComponentResolutionTest(component)
184+
SharedState.RunComponentResolutionTest(component, caller: caller)
184185
.Should().Pass()
185186
.And.HaveSuccessfullyResolvedComponentDependencies()
186187
.And.HaveResolvedComponentDependencyAssembly($"{component.AppDll};{expectedTestAssemblyPath}");

src/installer/tests/HostActivation.Tests/DependencyResolution/PerAssemblyVersionResolutionMultipleFrameworks.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Runtime.CompilerServices;
67
using Xunit;
78

89
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
@@ -75,7 +76,7 @@ public void AppWithExactlySameAssemblyAsFrameworkWithRollForward(string framewor
7576
TestAssemblyWithBothVersions, "2.1.1.1", "3.2.2.2", Constants.MicrosoftNETCoreApp);
7677
}
7778

78-
protected abstract void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, string testAssemblyName, string appAsmVersion, string appFileVersion, string frameWorkWins);
79+
protected abstract void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, string testAssemblyName, string appAsmVersion, string appFileVersion, string frameWorkWins, [CallerMemberName] string caller = "");
7980

8081
public class SharedTestState : ComponentSharedTestStateBase
8182
{
@@ -135,7 +136,7 @@ public AppPerAssemblyVersionResolutionMultipleFrameworks(SharedTestState sharedS
135136
{
136137
}
137138

138-
protected override void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, string testAssemblyName, string appAsmVersion, string appFileVersion, string frameworkWins)
139+
protected override void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, string testAssemblyName, string appAsmVersion, string appFileVersion, string frameworkWins, [CallerMemberName] string caller = "")
139140
{
140141
var app = SharedState.CreateTestFrameworkReferenceApp(b => b
141142
.WithPackage(TestVersionsPackage, "1.0.0", lib => lib
@@ -159,7 +160,7 @@ protected override void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, s
159160

160161
SharedState.DotNetWithNetCoreApp.Exec(app.AppDll)
161162
.EnableTracingAndCaptureOutputs()
162-
.Execute()
163+
.Execute(caller)
163164
.Should().Pass()
164165
.And.HaveResolvedAssembly(expectedTestAssemblyPath)
165166
.And.HaveUsedFrameworkProbe(SharedState.HighWarePath, level: 1)
@@ -176,7 +177,7 @@ public ComponentPerAssemblyVersionResolutionMultipleFrameworks(SharedTestState s
176177
{
177178
}
178179

179-
protected override void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, string testAssemblyName, string appAsmVersion, string appFileVersion, string frameworkWins)
180+
protected override void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, string testAssemblyName, string appAsmVersion, string appFileVersion, string frameworkWins, [CallerMemberName] string caller = "")
180181
{
181182
var component = SharedState.CreateComponentWithNoDependencies(b => b
182183
.WithPackage(TestVersionsPackage, "1.0.0", lib => lib
@@ -193,7 +194,7 @@ protected override void RunTest(Action<RuntimeConfig> runtimeConfigCustomizer, s
193194
// For component dependency resolution, frameworks are not considered, so the assembly from the component always wins
194195
string expectedTestAssemblyPath = Path.Combine(component.Location, testAssemblyName + ".dll");
195196

196-
SharedState.RunComponentResolutionTest(component)
197+
SharedState.RunComponentResolutionTest(component, caller: caller)
197198
.Should().Pass()
198199
.And.HaveSuccessfullyResolvedComponentDependencies()
199200
.And.HaveResolvedComponentDependencyAssembly($"{component.AppDll};{expectedTestAssemblyPath}")

src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8+
using System.Runtime.CompilerServices;
89
using Microsoft.DotNet.Cli.Build;
910
using Microsoft.Extensions.DependencyModel;
1011
using Xunit;
@@ -69,7 +70,8 @@ protected abstract void RunTest(
6970
Action<NetCoreAppBuilder.RuntimeLibraryBuilder> assetsCustomizer,
7071
TestSetup setup,
7172
ResolvedPaths expected,
72-
Action<NetCoreAppBuilder> appCustomizer = null);
73+
Action<NetCoreAppBuilder> appCustomizer = null,
74+
[CallerMemberName] string caller = "");
7375

7476
protected TestApp UpdateAppConfigForTest(TestApp app, TestSetup setup, bool copyOnUpdate)
7577
{
@@ -649,7 +651,8 @@ protected override void RunTest(
649651
Action<NetCoreAppBuilder.RuntimeLibraryBuilder> assetsCustomizer,
650652
TestSetup setup,
651653
ResolvedPaths expected,
652-
Action<NetCoreAppBuilder> appCustomizer)
654+
Action<NetCoreAppBuilder> appCustomizer,
655+
[CallerMemberName] string caller = "")
653656
{
654657
using (TestApp app = NetCoreAppBuilder.PortableForNETCoreApp(SharedState.FrameworkReferenceApp)
655658
.WithProject(p => { p.WithAssemblyGroup(null, g => g.WithMainAssembly()); assetsCustomizer?.Invoke(p); })
@@ -672,7 +675,7 @@ protected override void RunTest(
672675
var result = dotnet.Exec(app.AppDll)
673676
.EnableTracingAndCaptureOutputs()
674677
.RuntimeId(setup.Rid)
675-
.Execute();
678+
.Execute(caller);
676679
result.Should().Pass()
677680
.And.HaveResolvedAssembly(expected.IncludedAssemblyPaths, app)
678681
.And.NotHaveResolvedAssembly(expected.ExcludedAssemblyPaths, app)
@@ -703,7 +706,8 @@ protected override void RunTest(
703706
Action<NetCoreAppBuilder.RuntimeLibraryBuilder> assetsCustomizer,
704707
TestSetup setup,
705708
ResolvedPaths expected,
706-
Action<NetCoreAppBuilder> appCustomizer)
709+
Action<NetCoreAppBuilder> appCustomizer,
710+
[CallerMemberName] string caller = "")
707711
{
708712
var component = SharedState.CreateComponentWithNoDependencies(b => b
709713
.WithPackage("NativeDependency", "1.0.0", p => assetsCustomizer?.Invoke(p))
@@ -722,8 +726,12 @@ protected override void RunTest(
722726

723727
TestApp app = UpdateAppConfigForTest(SharedState.FrameworkReferenceApp, setup, copyOnUpdate: true);
724728

725-
var result = SharedState.RunComponentResolutionTest(component.AppDll, app, dotnet.GreatestVersionHostFxrPath, command => command
726-
.RuntimeId(setup.Rid));
729+
var result = SharedState.RunComponentResolutionTest(
730+
component.AppDll,
731+
app,
732+
dotnet.GreatestVersionHostFxrPath,
733+
command => command.RuntimeId(setup.Rid),
734+
caller: caller);
727735
result.Should().Pass()
728736
.And.HaveSuccessfullyResolvedComponentDependencies()
729737
.And.HaveResolvedComponentDependencyAssembly(expected.IncludedAssemblyPaths, component)
@@ -754,7 +762,8 @@ protected override void RunTest(
754762
Action<NetCoreAppBuilder.RuntimeLibraryBuilder> assetsCustomizer,
755763
TestSetup setup,
756764
ResolvedPaths expected,
757-
Action<NetCoreAppBuilder> appCustomizer)
765+
Action<NetCoreAppBuilder> appCustomizer,
766+
[CallerMemberName] string caller = "")
758767
{
759768
var component = SharedState.CreateComponentWithNoDependencies(b => b
760769
.WithPackage("NativeDependency", "1.0.0", p => assetsCustomizer?.Invoke(p))
@@ -773,8 +782,12 @@ protected override void RunTest(
773782

774783
app = UpdateAppConfigForTest(app, setup, copyOnUpdate: true);
775784

776-
var result = SharedState.RunComponentResolutionTest(component.AppDll, app, app.Location, command => command
777-
.RuntimeId(setup.Rid));
785+
var result = SharedState.RunComponentResolutionTest(
786+
component.AppDll,
787+
app,
788+
app.Location,
789+
command => command.RuntimeId(setup.Rid),
790+
caller: caller);
778791
result.Should().Pass()
779792
.And.HaveSuccessfullyResolvedComponentDependencies()
780793
.And.HaveResolvedComponentDependencyAssembly(expected.IncludedAssemblyPaths, component)

src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void Muxer_NonAssemblyWithExeExtension()
143143
TestContext.BuiltDotNet.Exec(appExe)
144144
.CaptureStdOut()
145145
.CaptureStdErr()
146-
.Execute()
146+
.Execute(expectedToFail: true)
147147
.Should().Fail()
148148
.And.HaveStdErrContaining("BadImageFormatException");
149149
}
@@ -466,7 +466,7 @@ public void AppHost_GUI_MissingRuntimeFramework_ErrorReportedInDialog()
466466
command.Process.Kill();
467467

468468
string expectedMissingFramework = $"'{Constants.MicrosoftNETCoreApp}', version '{TestContext.MicrosoftNETCoreAppVersion}' ({TestContext.BuildArchitecture})";
469-
var result = command.WaitForExit(true)
469+
var result = command.WaitForExit()
470470
.Should().Fail()
471471
.And.HaveStdErrContaining($"Showing error dialog for application: '{Path.GetFileName(appExe)}' - error code: 0x{expectedErrorCode}")
472472
.And.HaveStdErrContaining($"url: 'https://aka.ms/dotnet-core-applaunch?{expectedUrlQuery}")
@@ -496,7 +496,7 @@ public void AppHost_GUI_MissingRuntime_ErrorReportedInDialog()
496496
command.Process.Kill();
497497

498498
var expectedErrorCode = Constants.ErrorCode.CoreHostLibMissingFailure.ToString("x");
499-
var result = command.WaitForExit(true)
499+
var result = command.WaitForExit()
500500
.Should().Fail()
501501
.And.HaveStdErrContaining($"Showing error dialog for application: '{Path.GetFileName(appExe)}' - error code: 0x{expectedErrorCode}")
502502
.And.HaveStdErrContaining($"url: 'https://aka.ms/dotnet-core-applaunch?missing_runtime=true")
@@ -531,7 +531,7 @@ public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDial
531531
command.Process.Kill();
532532

533533
string expectedErrorCode = Constants.ErrorCode.FrameworkMissingFailure.ToString("x");
534-
command.WaitForExit(true)
534+
command.WaitForExit()
535535
.Should().Fail()
536536
.And.HaveStdErrContaining($"Showing error dialog for application: '{Path.GetFileName(appExe)}' - error code: 0x{expectedErrorCode}")
537537
.And.HaveStdErrContaining("You must install or update .NET to run this application.")

0 commit comments

Comments
 (0)