Skip to content

Commit cdd2273

Browse files
authored
Remove SharedFramework test helper in host tests in favor of TestArtifact (#98260)
- Remove `SharedFramework` test helper and use `TestArtifact` instead - Remove unnecessary base classes in dependency resolution tests
1 parent 030fd3b commit cdd2273

30 files changed

+322
-500
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ public void FrameworkDependent_NoBundleEntryPoint()
5858
{
5959
var singleFile = sharedTestState.FrameworkDependentApp.Bundle(BundleOptions.None);
6060

61-
string dotnetWithMockHostFxr = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "guiErrors"));
62-
using (new TestArtifact(dotnetWithMockHostFxr))
61+
using (var dotnetWithMockHostFxr = TestArtifact.Create("mockhostfxrFrameworkMissingFailure"))
6362
{
64-
Directory.CreateDirectory(dotnetWithMockHostFxr);
65-
var dotnetBuilder = new DotNetBuilder(dotnetWithMockHostFxr, TestContext.BuiltDotNet.BinPath, "mockhostfxrFrameworkMissingFailure")
63+
var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, TestContext.BuiltDotNet.BinPath, null)
6664
.RemoveHostFxr()
67-
.AddMockHostFxr(new Version(2, 2, 0));
68-
var dotnet = dotnetBuilder.Build();
65+
.AddMockHostFxr(new Version(2, 2, 0))
66+
.Build();
6967

7068
// Run the bundled app (extract files)
7169
RunTheApp(singleFile, dotnet.BinPath)
@@ -86,16 +84,15 @@ public void FrameworkDependent_GUI_DownlevelHostFxr_ErrorDialog(BundleOptions op
8684
var singleFile = sharedTestState.FrameworkDependentApp.Bundle(options);
8785
PEUtils.SetWindowsGraphicalUserInterfaceBit(singleFile);
8886

89-
string dotnetWithMockHostFxr = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "bundleErrors"));
90-
using (new TestArtifact(dotnetWithMockHostFxr))
87+
// The mockhostfxrBundleVersionFailure folder name is used by mock hostfxr to return the appropriate error code
88+
using (var dotnetWithMockHostFxr = TestArtifact.Create("mockhostfxrBundleVersionFailure"))
9189
{
92-
Directory.CreateDirectory(dotnetWithMockHostFxr);
9390
string expectedErrorCode = Constants.ErrorCode.BundleExtractionFailure.ToString("x");
9491

95-
var dotnetBuilder = new DotNetBuilder(dotnetWithMockHostFxr, TestContext.BuiltDotNet.BinPath, "mockhostfxrBundleVersionFailure")
92+
var dotnet = new DotNetBuilder(dotnetWithMockHostFxr.Location, TestContext.BuiltDotNet.BinPath, null)
9693
.RemoveHostFxr()
97-
.AddMockHostFxr(new Version(5, 0, 0));
98-
var dotnet = dotnetBuilder.Build();
94+
.AddMockHostFxr(new Version(5, 0, 0))
95+
.Build();
9996

10097
Command command = Command.Create(singleFile)
10198
.EnableTracingAndCaptureOutputs()

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
1111
{
12-
public class AdditionalDeps : DependencyResolutionBase, IClassFixture<AdditionalDeps.SharedTestState>
12+
public class AdditionalDeps : IClassFixture<AdditionalDeps.SharedTestState>
1313
{
1414
private SharedTestState SharedState { get; }
1515

@@ -41,13 +41,12 @@ public AdditionalDeps(SharedTestState sharedState)
4141
[InlineData("4.1.2-preview.2", new string[] { "4.0.0", "4.1.2", "4.2.0" }, null)]
4242
public void DepsDirectory(string fxVersion, string[] versions, string usedVersion)
4343
{
44-
string additionalDepsDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(SharedState.Location, "additionalDeps"));
45-
using (TestArtifact artifact = new TestArtifact(additionalDepsDirectory))
44+
using (TestArtifact additionalDeps = TestArtifact.Create("additionalDeps"))
4645
{
4746
string depsJsonName = Path.GetFileName(SharedState.AdditionalDepsComponent.DepsJson);
4847
foreach (string version in versions)
4948
{
50-
string path = Path.Combine(additionalDepsDirectory, "shared", MicrosoftNETCoreApp, version);
49+
string path = Path.Combine(additionalDeps.Location, "shared", Constants.MicrosoftNETCoreApp, version);
5150
Directory.CreateDirectory(path);
5251
File.Copy(
5352
SharedState.AdditionalDepsComponent.DepsJson,
@@ -61,12 +60,12 @@ public void DepsDirectory(string fxVersion, string[] versions, string usedVersio
6160
// Make a copy of the app and update its framework version
6261
app = SharedState.FrameworkReferenceApp.Copy();
6362
RuntimeConfig.FromFile(app.RuntimeConfigJson)
64-
.RemoveFramework(MicrosoftNETCoreApp)
65-
.WithFramework(MicrosoftNETCoreApp, fxVersion)
63+
.RemoveFramework(Constants.MicrosoftNETCoreApp)
64+
.WithFramework(Constants.MicrosoftNETCoreApp, fxVersion)
6665
.Save();
6766
}
6867

69-
CommandResult result = SharedState.DotNetWithNetCoreApp.Exec(Constants.AdditionalDeps.CommandLineArgument, additionalDepsDirectory, app.AppDll)
68+
CommandResult result = SharedState.DotNetWithNetCoreApp.Exec(Constants.AdditionalDeps.CommandLineArgument, additionalDeps.Location, app.AppDll)
7069
.EnableTracingAndCaptureOutputs()
7170
.Execute();
7271

@@ -77,7 +76,7 @@ public void DepsDirectory(string fxVersion, string[] versions, string usedVersio
7776
}
7877
else
7978
{
80-
result.Should().HaveUsedAdditionalDeps(Path.Combine(additionalDepsDirectory, "shared", MicrosoftNETCoreApp, usedVersion, depsJsonName));
79+
result.Should().HaveUsedAdditionalDeps(Path.Combine(additionalDeps.Location, "shared", Constants.MicrosoftNETCoreApp, usedVersion, depsJsonName));
8180
}
8281
}
8382
}
@@ -138,7 +137,7 @@ public void InvalidJson()
138137
}
139138
}
140139

141-
public class SharedTestState : DependencyResolutionBase.SharedTestStateBase
140+
public class SharedTestState : SharedTestStateBase
142141
{
143142
public DotNetCli DotNetWithNetCoreApp { get; }
144143

@@ -155,7 +154,7 @@ public SharedTestState()
155154

156155
AdditionalDepsComponent = CreateComponentWithNoDependencies();
157156

158-
FrameworkReferenceApp = CreateFrameworkReferenceApp(MicrosoftNETCoreApp, NetCoreAppVersion);
157+
FrameworkReferenceApp = CreateFrameworkReferenceApp(Constants.MicrosoftNETCoreApp, NetCoreAppVersion);
159158

160159
// Copy dependency next to app
161160
File.Copy(AdditionalDepsComponent.AppDll, Path.Combine(FrameworkReferenceApp.Location, $"{AdditionalDepsComponent.AssemblyName}.dll"));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
1111
{
12-
public class AdditionalProbingPath : DependencyResolutionBase, IClassFixture<AdditionalProbingPath.SharedTestState>
12+
public class AdditionalProbingPath : IClassFixture<AdditionalProbingPath.SharedTestState>
1313
{
1414
private readonly SharedTestState sharedState;
1515

@@ -90,7 +90,7 @@ public void RuntimeConfigSetting(bool dependencyExists)
9090
}
9191
}
9292

93-
public class SharedTestState : DependencyResolutionBase.SharedTestStateBase
93+
public class SharedTestState : SharedTestStateBase
9494
{
9595
public DotNetCli DotNetWithNetCoreApp { get; }
9696

@@ -115,7 +115,7 @@ public SharedTestState()
115115
.Build();
116116

117117
string nativeDependencyRelPath = $"{TestContext.TargetRID}/{Binaries.GetSharedLibraryFileNameForCurrentPlatform("native")}";
118-
FrameworkReferenceApp = CreateFrameworkReferenceApp(MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion, b => b
118+
FrameworkReferenceApp = CreateFrameworkReferenceApp(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion, b => b
119119
.WithProject(DependencyName, DependencyVersion, p => p
120120
.WithAssemblyGroup(null, g => g
121121
.WithAsset($"{DependencyName}.dll", f => f.NotOnDisk()))

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

Lines changed: 0 additions & 106 deletions
This file was deleted.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.DotNet.Cli.Build;
5+
using Microsoft.DotNet.Cli.Build.Framework;
6+
using System;
7+
using System.IO;
8+
9+
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
10+
{
11+
public abstract class ComponentSharedTestStateBase : SharedTestStateBase
12+
{
13+
private const string resolve_component_dependencies = "resolve_component_dependencies";
14+
private const string run_app_and_resolve = "run_app_and_resolve";
15+
private const string run_app_and_resolve_multithreaded = "run_app_and_resolve_multithreaded";
16+
17+
public DotNetCli DotNetWithNetCoreApp { get; }
18+
19+
public TestApp FrameworkReferenceApp { get; }
20+
21+
public string NativeHostPath { get => _nativeHostingState.NativeHostPath; }
22+
23+
private readonly NativeHosting.SharedTestStateBase _nativeHostingState;
24+
25+
public ComponentSharedTestStateBase()
26+
{
27+
var dotNetBuilder = DotNet("WithNetCoreApp")
28+
.AddMicrosoftNETCoreAppFrameworkMockCoreClr("4.0.0", builder => CustomizeDotNetWithNetCoreAppMicrosoftNETCoreApp(builder));
29+
CustomizeDotNetWithNetCoreApp(dotNetBuilder);
30+
DotNetWithNetCoreApp = dotNetBuilder.Build();
31+
32+
FrameworkReferenceApp = CreateTestFrameworkReferenceApp();
33+
34+
_nativeHostingState = new NativeHosting.SharedTestStateBase();
35+
}
36+
37+
protected virtual TestApp CreateTestFrameworkReferenceApp() => CreateFrameworkReferenceApp(Constants.MicrosoftNETCoreApp, "4.0.0");
38+
39+
protected virtual void CustomizeDotNetWithNetCoreAppMicrosoftNETCoreApp(NetCoreAppBuilder builder)
40+
{
41+
}
42+
43+
protected virtual void CustomizeDotNetWithNetCoreApp(DotNetBuilder builder)
44+
{
45+
}
46+
47+
public CommandResult RunComponentResolutionTest(TestApp component, Action<Command> commandCustomizer = null)
48+
{
49+
return RunComponentResolutionTest(component.AppDll, FrameworkReferenceApp, DotNetWithNetCoreApp.GreatestVersionHostFxrPath, commandCustomizer);
50+
}
51+
52+
public CommandResult RunComponentResolutionTest(string componentPath, TestApp hostApp, string hostFxrFolder, Action<Command> commandCustomizer = null)
53+
{
54+
string[] args =
55+
{
56+
resolve_component_dependencies,
57+
run_app_and_resolve,
58+
Path.Combine(hostFxrFolder, Binaries.HostFxr.FileName),
59+
hostApp.AppDll,
60+
componentPath
61+
};
62+
63+
Command command = Command.Create(NativeHostPath, args)
64+
.EnableTracingAndCaptureOutputs()
65+
.MultilevelLookup(false);
66+
commandCustomizer?.Invoke(command);
67+
68+
return command.Execute()
69+
.StdErrAfter("corehost_resolve_component_dependencies = {");
70+
}
71+
72+
public CommandResult RunComponentResolutionMultiThreadedTest(TestApp componentOne, TestApp componentTwo)
73+
{
74+
return RunComponentResolutionMultiThreadedTest(componentOne.AppDll, componentTwo.AppDll, FrameworkReferenceApp, DotNetWithNetCoreApp.GreatestVersionHostFxrPath);
75+
}
76+
77+
public CommandResult RunComponentResolutionMultiThreadedTest(string componentOnePath, string componentTwoPath, TestApp hostApp, string hostFxrFolder)
78+
{
79+
string[] args =
80+
{
81+
resolve_component_dependencies,
82+
run_app_and_resolve_multithreaded,
83+
Path.Combine(hostFxrFolder, Binaries.HostFxr.FileName),
84+
hostApp.AppDll,
85+
componentOnePath,
86+
componentTwoPath
87+
};
88+
89+
return Command.Create(NativeHostPath, args)
90+
.EnableTracingAndCaptureOutputs()
91+
.MultilevelLookup(false)
92+
.Execute();
93+
}
94+
95+
protected override void Dispose(bool disposing)
96+
{
97+
FrameworkReferenceApp.Dispose();
98+
_nativeHostingState.Dispose();
99+
base.Dispose(disposing);
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)