Skip to content

Fix FrameworkDependentAppLaunch.AppHost_GlobalLocation 'Failed to restore file' CI failure #116831

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 @@ -187,83 +187,17 @@ public void AppHost()
if (Binaries.CetCompat.IsSupported)
Assert.True(Binaries.CetCompat.IsMarkedCompatible(appExe));

// Get the framework location that was built
string builtDotnet = TestContext.BuiltDotNet.BinPath;

// Verify running with the default working directory
Command.Create(appExe)
.CaptureStdErr()
.CaptureStdOut()
.DotNetRoot(builtDotnet, TestContext.BuildArchitecture)
.MultilevelLookup(false)
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
.And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion);


// Verify running from within the working directory
Command.Create(appExe)
.WorkingDirectory(sharedTestState.App.Location)
.DotNetRoot(builtDotnet, TestContext.BuildArchitecture)
.DotNetRoot(TestContext.BuiltDotNet.BinPath, TestContext.BuildArchitecture)
.MultilevelLookup(false)
.CaptureStdErr()
.CaptureStdOut()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
.And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void AppHost_GlobalLocation(bool useRegisteredLocation)
{
string appExe = sharedTestState.App.AppExe;

// Get the framework location that was built
string builtDotnet = TestContext.BuiltDotNet.BinPath;

using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe))
{
string architecture = TestContext.BuildArchitecture;
if (useRegisteredLocation)
{
registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] { (architecture, builtDotnet) });
}

// Verify running with the default working directory
Command.Create(appExe)
.CaptureStdErr()
.CaptureStdOut()
.MultilevelLookup(false)
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
.DotNetRoot(null)
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
.And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion)
.And.NotHaveStdErr();

// Verify running from within the working directory
Command.Create(appExe)
.CaptureStdErr()
.CaptureStdOut()
.MultilevelLookup(false)
.WorkingDirectory(sharedTestState.App.Location)
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
.DotNetRoot(null)
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
.And.HaveStdOutContaining(TestContext.MicrosoftNETCoreAppVersion)
.And.NotHaveStdErr();
}
}

[ConditionalFact(typeof(Binaries.CetCompat), nameof(Binaries.CetCompat.IsSupported))]
public void AppHost_DisableCetCompat()
{
Expand Down
119 changes: 80 additions & 39 deletions src/installer/tests/HostActivation.Tests/InstallLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void EnvironmentVariable_ArchSpecificDotnetRootIsUsedOverDotnetRoot()
[Fact]
public void EnvironmentVariable_DotNetRootIsUsedOverInstallLocationIfSet()
{
var app = sharedTestState.App.Copy();
var app = sharedTestState.TestBehaviourEnabledApp;
var appExe = app.AppExe;
var arch = TestContext.BuildArchitecture.ToUpper();
var dotnet = TestContext.BuiltDotNet.BinPath;
Expand All @@ -87,44 +87,38 @@ public void EnvironmentVariable_DotNetRootIsUsedOverInstallLocationIfSet()
[Fact]
public void EnvironmentVariable_DotnetRootPathDoesNotExist()
{
var app = sharedTestState.App.Copy();
using (TestOnlyProductBehavior.Enable(app.AppExe))
{
Command.Create(app.AppExe)
.EnableTracingAndCaptureOutputs()
.DotNetRoot("non_existent_path")
.MultilevelLookup(false)
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.GloballyRegisteredPath,
TestContext.BuiltDotNet.BinPath)
.Execute()
.Should().Pass()
.And.HaveStdErrContaining("Did not find [DOTNET_ROOT] directory [non_existent_path]")
// If DOTNET_ROOT points to a folder that does not exist, we fall back to the global install path.
.And.HaveUsedGlobalInstallLocation(TestContext.BuiltDotNet.BinPath)
.And.HaveStdOutContaining("Hello World");
}
var app = sharedTestState.TestBehaviourEnabledApp;
Command.Create(app.AppExe)
.EnableTracingAndCaptureOutputs()
.DotNetRoot("non_existent_path")
.MultilevelLookup(false)
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.GloballyRegisteredPath,
TestContext.BuiltDotNet.BinPath)
.Execute()
.Should().Pass()
.And.HaveStdErrContaining("Did not find [DOTNET_ROOT] directory [non_existent_path]")
// If DOTNET_ROOT points to a folder that does not exist, we fall back to the global install path.
.And.HaveUsedGlobalInstallLocation(TestContext.BuiltDotNet.BinPath)
.And.HaveStdOutContaining("Hello World");
}

[Fact]
public void EnvironmentVariable_DotnetRootPathExistsButHasNoHost()
{
var app = sharedTestState.App.Copy();
using (TestOnlyProductBehavior.Enable(app.AppExe))
{
Command.Create(app.AppExe)
.EnableTracingAndCaptureOutputs()
.DotNetRoot(app.Location)
.MultilevelLookup(false)
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.GloballyRegisteredPath,
TestContext.BuiltDotNet.BinPath)
.Execute()
.Should().Fail()
.And.HaveUsedDotNetRootInstallLocation(app.Location, TestContext.BuildRID)
// If DOTNET_ROOT points to a folder that exists we assume that there's a dotnet installation in it
.And.HaveStdErrContaining($"The required library {Binaries.HostFxr.FileName} could not be found.");
}
var app = sharedTestState.TestBehaviourEnabledApp;
Command.Create(app.AppExe)
.EnableTracingAndCaptureOutputs()
.DotNetRoot(app.Location)
.MultilevelLookup(false)
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.GloballyRegisteredPath,
TestContext.BuiltDotNet.BinPath)
.Execute()
.Should().Fail()
.And.HaveUsedDotNetRootInstallLocation(app.Location, TestContext.BuildRID)
// If DOTNET_ROOT points to a folder that exists we assume that there's a dotnet installation in it
.And.HaveStdErrContaining($"The required library {Binaries.HostFxr.FileName} could not be found.");
}

[Fact]
Expand Down Expand Up @@ -163,10 +157,49 @@ public void EnvironmentVariable_DotNetInfo_ListEnvironment()
}
}

[Fact]
public void DefaultInstallLocation()
{
TestApp app = sharedTestState.TestBehaviourEnabledApp;

// Ensure no install locations are registered, so the default install location is used
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(app.AppExe))
{
Command.Create(app.AppExe)
.EnableTracingAndCaptureOutputs()
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, TestContext.BuiltDotNet.BinPath)
.DotNetRoot(null)
.Execute()
.Should().Pass()
.And.HaveUsedGlobalInstallLocation(TestContext.BuiltDotNet.BinPath);
}
}

[Fact]
public void RegisteredInstallLocation()
{
TestApp app = sharedTestState.TestBehaviourEnabledApp;
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(app.AppExe))
{
registeredInstallLocationOverride.SetInstallLocation(
(TestContext.BuildArchitecture, TestContext.BuiltDotNet.BinPath));

Command.Create(app.AppExe)
.EnableTracingAndCaptureOutputs()
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.DotNetRoot(null)
.Execute()
.Should().Pass()
.And.HaveUsedRegisteredInstallLocation(TestContext.BuiltDotNet.BinPath)
.And.HaveUsedGlobalInstallLocation(TestContext.BuiltDotNet.BinPath);
}
}

[Fact]
public void RegisteredInstallLocation_ArchSpecificLocationIsPickedFirst()
{
var app = sharedTestState.App.Copy();
var app = sharedTestState.TestBehaviourEnabledApp;
var arch1 = "someArch";
var path1 = "x/y/z";
var arch2 = TestContext.BuildArchitecture;
Expand Down Expand Up @@ -202,7 +235,7 @@ public void RegisteredInstallLocation_ArchSpecificLocationIsPickedFirst()
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void InstallLocationFile_ReallyLongInstallPathIsParsedCorrectly()
{
var app = sharedTestState.App.Copy();
var app = sharedTestState.TestBehaviourEnabledApp;
using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(app.AppExe))
{
var reallyLongPath =
Expand All @@ -225,9 +258,8 @@ public void InstallLocationFile_ReallyLongInstallPathIsParsedCorrectly()
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void InstallLocationFile_MissingFile()
{
var app = sharedTestState.App.Copy();
var app = sharedTestState.TestBehaviourEnabledApp;
using (var testArtifact = TestArtifact.Create("missingInstallLocation"))
using (var testOnlyProductBehavior = TestOnlyProductBehavior.Enable(app.AppExe))
{
string installLocationDirectory = Path.Combine(testArtifact.Location, "installLocationOverride");
Directory.CreateDirectory(installLocationDirectory);
Expand Down Expand Up @@ -345,7 +377,7 @@ public void SearchOptions(SearchLocation searchLocation)
}

[Fact]
public void AppHost_AppRelative_MissingPath()
public void SearchOptions_AppRelative_MissingPath()
{
TestApp app = sharedTestState.App.Copy();
app.CreateAppHost(dotNetRootOptions: new HostWriter.DotNetSearchOptions()
Expand Down Expand Up @@ -450,16 +482,25 @@ public void SearchOptions_Precedence(SearchLocation expectedResult)
public class SharedTestState : IDisposable
{
public TestApp App { get; }
public TestApp TestBehaviourEnabledApp { get; }

public SharedTestState()
{
App = TestApp.CreateFromBuiltAssets("HelloWorld");
App.CreateAppHost();

TestBehaviourEnabledApp = TestApp.CreateFromBuiltAssets("HelloWorld");
TestBehaviourEnabledApp.CreateAppHost();

// Enable test-only behavior for the app. We don't bother disabling the behaviour later,
// as we just delete the entire app after the tests run.
_ = TestOnlyProductBehavior.Enable(TestBehaviourEnabledApp.AppExe);
}

public void Dispose()
{
App?.Dispose();
TestBehaviourEnabledApp?.Dispose();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/installer/tests/TestUtils/TestFileBackup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static void CopyOverDirectory(string source, string destination)
}
}

private static void RetryOnIOError(Func<bool> action, string errorMessage, int maxRetries = 5)
private static void RetryOnIOError(Func<bool> action, string errorMessage, int maxRetries = 25)
{
IOException exception = null;
for (int i = 0; i < maxRetries; i++)
Expand All @@ -119,7 +119,7 @@ private static void RetryOnIOError(Func<bool> action, string errorMessage, int m
return;
}
}
catch (IOException e)
catch (IOException e)
{
exception = e;
}
Expand Down
Loading