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

Use temp directory as TestExecutionDirectory in RunTestsOnHelix.sh #45022

Open
wants to merge 9 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
5 changes: 2 additions & 3 deletions build/RunTestsOnHelix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export MicrosoftNETBuildExtensionsTargets=$HELIX_CORRELATION_PAYLOAD/ex/msbuildE
export DOTNET_ROOT=$HELIX_CORRELATION_PAYLOAD/d
export PATH=$DOTNET_ROOT:$PATH

export TestExecutionDirectory=$(pwd)/testExecutionDirectory
mkdir $TestExecutionDirectory
export TestExecutionDirectory=$(realpath "$(mktemp -d "${TMPDIR:-/tmp}"/dotnetSdkTests.XXXXXXXX)")
export DOTNET_CLI_HOME=$TestExecutionDirectory/.dotnet
cp -a $HELIX_CORRELATION_PAYLOAD/t/TestExecutionDirectoryFiles/. $TestExecutionDirectory/

Expand All @@ -36,4 +35,4 @@ dotnet nuget remove source dotnet-libraries-transport --configfile $TestExecutio
dotnet nuget remove source dotnet-tools-transport --configfile $TestExecutionDirectory/NuGet.config
dotnet nuget remove source dotnet-libraries --configfile $TestExecutionDirectory/NuGet.config
dotnet nuget remove source dotnet-eng --configfile $TestExecutionDirectory/NuGet.config
dotnet nuget list source --configfile $TestExecutionDirectory/NuGet.config
dotnet nuget list source --configfile $TestExecutionDirectory/NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public override bool Execute()
{
if (!File.Exists(ScriptFullPath))
{
File.Create(ScriptFullPath);
File.Create(ScriptFullPath).Close();
}

File.WriteAllLines(ScriptFullPath, GetReplacedFileContents(Resources.MsDeployBatchFile));

if (!File.Exists(ReadMeFullPath))
{
File.Create(ReadMeFullPath);
File.Create(ReadMeFullPath).Close();
}

File.WriteAllLines(ReadMeFullPath, GetReplacedFileContents(Resources.MsDeployReadMe));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override bool Execute()
{
if (!File.Exists(ManifestFile))
{
File.Create(ManifestFile);
File.Create(ManifestFile).Close();
}
WriteManifestsToFile(Log, m_manifests, ManifestFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public override bool Execute()
{
if (!File.Exists(DeclareSetParameterFile))
{
File.Create(DeclareSetParameterFile);
File.Create(DeclareSetParameterFile).Close();
}

if (!string.IsNullOrEmpty(DeclareParameterFile))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ private async Task<List<ITaskItem>> PrepareWorkItem(ITaskItem xunitProject)
throw new NotImplementedException("does not support non support the runtime specified");
}

// On mac due to https://github.com/dotnet/sdk/issues/3923, we run against workitem directory
// but on Windows, if we running against working item diretory, we would hit long path.
string testExecutionDirectory = netFramework ? "-e DOTNET_SDK_TEST_EXECUTION_DIRECTORY=%TestExecutionDirectory%" : IsPosixShell ? "-testExecutionDirectory $TestExecutionDirectory" : "-testExecutionDirectory %TestExecutionDirectory%";

string msbuildAdditionalSdkResolverFolder = netFramework ? "-e DOTNET_SDK_TEST_MSBUILDSDKRESOLVER_FOLDER=%HELIX_CORRELATION_PAYLOAD%\\r" : IsPosixShell ? "" : "-msbuildAdditionalSdkResolverFolder %HELIX_CORRELATION_PAYLOAD%\\r";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ItIgnoresInvalidPath()
[Fact]
public void ItDoesNotReturnNullDotnetRootOnExtraPathSeparator()
{
File.Create(Path.Combine(Directory.GetCurrentDirectory(), "dotnet.exe"));
File.Create(Path.Combine(Directory.GetCurrentDirectory(), "dotnet.exe")).Close();
Func<string, string> getPathEnvVarFunc = (input) => input.Equals("PATH") ? $"fake{Path.PathSeparator}" : string.Empty;
var result = NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory(getPathEnvVarFunc);
result.Should().NotBeNullOrWhiteSpace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void GivenManagedInstallItCanGetFeatureBandsWhenFilesArePresent()
{
string path = Path.Combine(dotnetRoot, "metadata", "workloads", version.ToString(), "InstalledWorkloads");
Directory.CreateDirectory(path);
File.Create(Path.Combine(path, "6.0.100"));
File.Create(Path.Combine(path, "6.0.100")).Close();
}

IEnumerable<SdkFeatureBand> featureBands = installer.GetWorkloadInstallationRecordRepository().GetFeatureBandsWithInstallationRecords();
Expand Down Expand Up @@ -357,7 +357,7 @@ public void GivenManagedInstallItCanGetDownloads()
// Write workload install record
var workloadsRecordPath = Path.Combine(dotnetRoot, "metadata", "workloads", version, "InstalledWorkloads");
Directory.CreateDirectory(workloadsRecordPath);
File.Create(Path.Combine(workloadsRecordPath, "android-sdk-workload"));
File.Create(Path.Combine(workloadsRecordPath, "android-sdk-workload")).Close();

var downloads = installer.GetDownloads(new[] { new WorkloadId("android-sdk-workload"), new WorkloadId("android-buildtools-workload") }, new SdkFeatureBand(version), false).ToList();

Expand All @@ -384,7 +384,7 @@ public void GivenManagedInstallItCanInstallPacksFromOfflineCache()
// Write mock cache
Directory.CreateDirectory(cachePath);
var nupkgPath = Path.Combine(cachePath, $"{packId}.{packVersion}.nupkg");
File.Create(nupkgPath);
File.Create(nupkgPath).Close();

CliTransaction.RunNew(context => installer.InstallWorkloads(new[] { new WorkloadId("android-sdk-workload") }, new SdkFeatureBand(version), context, new DirectoryPath(cachePath)));
var mockNugetInstaller = nugetInstaller as MockNuGetPackageDownloader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task GivenAdvertisingManifestUpdateItDoesNotUpdateWhenNotDue()
{
(var manifestUpdater, var nugetDownloader, var sentinelPath) = GetTestUpdater();

File.Create(sentinelPath);
File.Create(sentinelPath).Close();
var createTime = DateTime.Now;

await manifestUpdater.BackgroundUpdateAdvertisingManifestsWhenRequiredAsync();
Expand Down Expand Up @@ -242,7 +242,7 @@ public async Task ItCanFallbackAndAdvertiseCorrectUpdate(bool useOfflineCache)
{
offlineCacheDir = Path.Combine(testDir, "offlineCache");
Directory.CreateDirectory(offlineCacheDir);
File.Create(Path.Combine(offlineCacheDir, $"{testManifestName}.Manifest-6.0.200.nupkg"));
File.Create(Path.Combine(offlineCacheDir, $"{testManifestName}.Manifest-6.0.200.nupkg")).Close();

await manifestUpdater.UpdateAdvertisingManifestsAsync(includePreviews: true, offlineCache: new DirectoryPath(offlineCacheDir));
}
Expand Down Expand Up @@ -550,8 +550,8 @@ public async Task GivenWorkloadManifestUpdateItChoosesHighestManifestVersionInCa
// Write multiple manifest packages to the offline cache
var offlineCache = Path.Combine(testDir, "cache");
Directory.CreateDirectory(offlineCache);
File.Create(Path.Combine(offlineCache, $"{manifestId}.manifest-{featureBand}.2.0.0.nupkg"));
File.Create(Path.Combine(offlineCache, $"{manifestId}.manifest-{featureBand}.3.0.0.nupkg"));
File.Create(Path.Combine(offlineCache, $"{manifestId}.manifest-{featureBand}.2.0.0.nupkg")).Close();
File.Create(Path.Combine(offlineCache, $"{manifestId}.manifest-{featureBand}.3.0.0.nupkg")).Close();

var workloadManifestProvider = new MockManifestProvider(new string[] { Path.Combine(installedManifestDir, manifestId, _manifestFileName) });
var nugetDownloader = new MockNuGetPackageDownloader(dotnetRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void GivenManagedInstallItCanGarbageCollect()
// Write workload install record for 6.0.300
var workloadsRecordPath = Path.Combine(_dotnetRoot, "metadata", "workloads", sdkVersions[1], "InstalledWorkloads");
Directory.CreateDirectory(workloadsRecordPath);
File.Create(Path.Combine(workloadsRecordPath, "xamarin-android-build"));
File.Create(Path.Combine(workloadsRecordPath, "xamarin-android-build")).Close();

installer.GarbageCollect(getResolver);

Expand Down Expand Up @@ -130,7 +130,7 @@ public void GarbageCollectManifests()
// Write workload install record for xamarin-android-build workload for 6.0.300
var workloadsRecordPath = Path.Combine(_dotnetRoot, "metadata", "workloads", "6.0.300", "InstalledWorkloads");
Directory.CreateDirectory(workloadsRecordPath);
File.Create(Path.Combine(workloadsRecordPath, "xamarin-android-build"));
File.Create(Path.Combine(workloadsRecordPath, "xamarin-android-build")).Close();

// These packs are referenced by xamarin-android-build from the 3.0 manifest, which is the latest one and therefore the one that will be kept
var packsToKeep = new PackInfo[]
Expand Down Expand Up @@ -210,7 +210,7 @@ public void GarbageCollectManifestsWithInstallState()
// Write workload install record for xamarin-android-build workload for 6.0.300
var workloadsRecordPath = Path.Combine(_dotnetRoot, "metadata", "workloads", "6.0.300", "InstalledWorkloads");
Directory.CreateDirectory(workloadsRecordPath);
File.Create(Path.Combine(workloadsRecordPath, "xamarin-android-build"));
File.Create(Path.Combine(workloadsRecordPath, "xamarin-android-build")).Close();

// These packs are referenced by xamarin-android-build from the 2.0 manifest, which is the one that should be kept due to the install state
var packsToKeep = new PackInfo[]
Expand Down
11 changes: 8 additions & 3 deletions test/dotnet-workload-update.Tests/GivenDotnetWorkloadUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public void GivenWorkloadUpdateAcrossFeatureBandsItUpdatesPacks(bool userLocal)
var sdkFeatureVersion = "6.0.100";
var installingWorkload = "simple-workload";

// Mock up a 5.0.1xx SDK install so that the installation records for that feature band won't be deleted
string dotnetDllPath = Path.Combine(dotnetRoot, "sdk", "5.0.110", "dotnet.dll");
Directory.CreateDirectory(Path.GetDirectoryName(dotnetDllPath));
File.Create(dotnetDllPath).Close();

string installRoot = userLocal ? userProfileDir : dotnetRoot;
if (userLocal)
{
Expand All @@ -228,12 +233,12 @@ public void GivenWorkloadUpdateAcrossFeatureBandsItUpdatesPacks(bool userLocal)
foreach (var pack in workloadPacks)
{
Directory.CreateDirectory(Path.Combine(packRecordDir, pack.Id, pack.Version));
File.Create(Path.Combine(packRecordDir, pack.Id, pack.Version, oldFeatureBand));
File.Create(Path.Combine(packRecordDir, pack.Id, pack.Version, oldFeatureBand)).Close();
}
Directory.CreateDirectory(Path.Combine(installRoot, "metadata", "workloads", oldFeatureBand, "InstalledWorkloads"));
Directory.CreateDirectory(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads"));
File.Create(Path.Combine(installRoot, "metadata", "workloads", oldFeatureBand, "InstalledWorkloads", installingWorkload));
File.Create(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads", installingWorkload));
File.Create(Path.Combine(installRoot, "metadata", "workloads", oldFeatureBand, "InstalledWorkloads", installingWorkload)).Close();
File.Create(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads", installingWorkload)).Close();

// Update workload (without installing any workloads to this feature band)
var updateParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--from-previous-sdk" });
Expand Down