Skip to content

Commit

Permalink
Workload VM test improvements (#42021)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpopMSFT authored Jul 9, 2024
2 parents 4f75e80 + 16061ef commit 73e0054
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 41 deletions.
44 changes: 25 additions & 19 deletions src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,11 @@ protected void InstallSdk(bool deployStage2 = true)
.Should()
.Pass();

var sdkTestingDir = VM.GetRemoteDirectory(@"c:\SdkTesting");
List<string> runtimeInstallers = new List<string>();
string installerPrefix = "dotnet-runtime-";
string installerSuffix = "-win-x64.exe";
foreach (var file in sdkTestingDir.Files.Select(Path.GetFileName))
{
if (file.StartsWith(installerPrefix) && file.EndsWith(installerSuffix))
{
runtimeInstallers.Add(file);
}
}
VM.CreateRunCommand($@"c:\SdkTesting\{SdkInstallerFileName}", "/quiet")
.WithDescription($"Install SDK {SdkInstallerVersion}")
.Execute().Should().Pass();

VM.CreateActionGroup($"Install SDK {SdkInstallerVersion}",
[
VM.CreateRunCommand($@"c:\SdkTesting\{SdkInstallerFileName}", "/quiet"),
..runtimeInstallers.Select(i => VM.CreateRunCommand($@"c:\SdkTesting\{i}", "/quiet"))
])
.Execute()
.Should()
.Pass();


if (deployStage2)
{
Expand All @@ -109,6 +94,27 @@ protected void DeployStage2Sdk()
return;
}


// Install any runtimes that are in the c:\SdkTesting directory, to support using older baseline SDK versions with a newer stage 2
var sdkTestingDir = VM.GetRemoteDirectory(@"c:\SdkTesting");
List<string> runtimeInstallers = new List<string>();
string installerPrefix = "dotnet-runtime-";
string installerSuffix = "-win-x64.exe";
foreach (var file in sdkTestingDir.Files.Select(Path.GetFileName))
{
if (file.StartsWith(installerPrefix) && file.EndsWith(installerSuffix))
{
runtimeInstallers.Add(file);
}
}

if (runtimeInstallers.Any())
{
VM.CreateActionGroup($"Install .NET runtime(s)",
runtimeInstallers.Select(i => VM.CreateRunCommand($@"c:\SdkTesting\{i}", "/quiet")).ToArray())
.Execute().Should().Pass();
}

var result = VM.CreateRunCommand("dotnet", "--version")
.WithIsReadOnly(true)
.Execute();
Expand Down
76 changes: 54 additions & 22 deletions src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.DotNet.MsiInstallerTests.Framework;
using Microsoft.NET.Sdk.WorkloadManifestReader;
Expand All @@ -17,8 +18,24 @@ public class WorkloadSetTests : VMTestBase
{
readonly string SdkTestingDirectory = @"C:\SdkTesting";


Lazy<Dictionary<string, string>> _testWorkloadSetVersions;
string WorkloadSetVersion1 => _testWorkloadSetVersions.Value.GetValueOrDefault("version1", "8.0.300-preview.0.24178.1");
string WorkloadSetVersion2 => _testWorkloadSetVersions.Value.GetValueOrDefault("version2", "8.0.300-preview.0.24217.2");
string WorkloadSetPreviousBandVersion => _testWorkloadSetVersions.Value.GetValueOrDefault("previousbandversion", "8.0.204");

public WorkloadSetTests(ITestOutputHelper log) : base(log)
{
_testWorkloadSetVersions = new Lazy<Dictionary<string, string>>(() =>
{
var versionsFile = VM.GetRemoteFile(@"c:\SdkTesting\workloadsets\testworkloadsetversions.json");
if (!versionsFile.Exists)
{
return new Dictionary<string, string>();
}

return JsonSerializer.Deserialize<Dictionary<string, string>>(versionsFile.ReadAllText());
});
}

[Fact]
Expand Down Expand Up @@ -91,7 +108,7 @@ public void UpdateWithWorkloadSets()

newRollback.ManifestVersions.Should().NotBeEquivalentTo(rollbackAfterUpdate.ManifestVersions);

GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
}

[Fact]
Expand All @@ -113,10 +130,19 @@ public void UpdateInWorkloadSetModeWithNoAvailableWorkloadSet()
GetWorkloadVersion().Should().Be(updatedWorkloadVersion);
}

[Theory]
[InlineData("8.0.300-preview.0.24178.1")]
[InlineData("8.0.204")]
public void UpdateToSpecificWorkloadSetVersion(string versionToInstall)
[Fact]
public void UpdateToSpecificWorkloadSetVersion()
{
UpdateToWorkloadSetVersion(WorkloadSetVersion1);
}

[Fact]
public void UpdateToPreviousBandWorkloadSetVersion()
{
UpdateToWorkloadSetVersion(WorkloadSetPreviousBandVersion);
}

private void UpdateToWorkloadSetVersion(string versionToInstall)
{
InstallSdk();

Expand Down Expand Up @@ -148,7 +174,7 @@ public void UpdateToSpecificWorkloadSetVersion(string versionToInstall)
.Should()
.Pass();

GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
}

[Fact]
Expand Down Expand Up @@ -207,7 +233,7 @@ public void UpdateToWorkloadSetVersionWithManifestsNotAvailable()

var workloadVersionBeforeUpdate = GetWorkloadVersion();

VM.CreateRunCommand("dotnet", "workload", "update", "--version", @"8.0.300-preview.0.24217.2", "--source", @"c:\SdkTesting\workloadsets")
VM.CreateRunCommand("dotnet", "workload", "update", "--version", WorkloadSetVersion2, "--source", @"c:\SdkTesting\workloadsets")
.Execute()
.Should()
.Fail();
Expand All @@ -225,7 +251,7 @@ void SetupWorkloadSetInGlobalJson(out WorkloadSet originalRollback)
{
InstallSdk();

var versionToUpdateTo = "8.0.300-preview.0.24217.2";
var versionToUpdateTo = WorkloadSetVersion2;

string originalVersion = GetWorkloadVersion();

Expand Down Expand Up @@ -286,7 +312,7 @@ public void InstallWithVersionAndSkipManifestUpdate()
{
InstallSdk();

VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--skip-manifest-update", "--version", "8.0.300-preview.0.24178.1")
VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--skip-manifest-update", "--version", WorkloadSetVersion1)
.Execute().Should().Fail()
.And.HaveStdErrContaining("--skip-manifest-update")
.And.HaveStdErrContaining("--sdk-version");
Expand All @@ -300,17 +326,17 @@ public void InstallWithVersionWhenPinned()
AddNuGetSource(@"c:\SdkTesting\WorkloadSets");

string originalVersion = GetWorkloadVersion();
originalVersion.Should().NotBe("8.0.300-preview.0.24178.1");
originalVersion.Should().NotBe(WorkloadSetVersion1);

VM.CreateRunCommand("dotnet", "workload", "update", "--version", "8.0.300-preview.0.24178.1")
VM.CreateRunCommand("dotnet", "workload", "update", "--version", WorkloadSetVersion1)
.Execute().Should().Pass();

GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1");
GetWorkloadVersion().Should().Be(WorkloadSetVersion1);

VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--version", "8.0.300-preview.0.24217.2")
VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--version", WorkloadSetVersion2)
.Execute().Should().Pass();

GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
}

[Fact]
Expand All @@ -321,18 +347,18 @@ public void InstallWithGlobalJsonWhenPinned()
//AddNuGetSource(@"c:\SdkTesting\WorkloadSets");

string originalVersion = GetWorkloadVersion();
originalVersion.Should().NotBe("8.0.300-preview.0.24178.1");
originalVersion.Should().NotBe(WorkloadSetVersion1);

VM.CreateRunCommand("dotnet", "workload", "update", "--version", "8.0.300-preview.0.24178.1")
VM.CreateRunCommand("dotnet", "workload", "update", "--version", WorkloadSetVersion1)
.Execute().Should().Pass();

GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1");
GetWorkloadVersion().Should().Be(WorkloadSetVersion1);

VM.CreateRunCommand("dotnet", "workload", "install", "aspire")
.WithWorkingDirectory(SdkTestingDirectory)
.Execute().Should().Pass();

GetWorkloadVersion(SdkTestingDirectory).Should().Be("8.0.300-preview.0.24217.2");
GetWorkloadVersion(SdkTestingDirectory).Should().Be(WorkloadSetVersion2);

GetRollback(SdkTestingDirectory).Should().NotBe(originalRollback);

Expand All @@ -346,22 +372,28 @@ public void UpdateShouldNotPinWorkloadSet()

AddNuGetSource(@"c:\SdkTesting\WorkloadSets");

var packageVersion = WorkloadSet.WorkloadSetVersionToWorkloadSetPackageVersion(WorkloadSetVersion2, out var sdkFeatureBand);

// Rename latest workload set so it won't be installed
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.nupkg", $"Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.bak")
VM.CreateActionGroup($"Disable {WorkloadSetVersion2}",
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.nupkg", $"Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.bak"),
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.nupkg", $"Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.bak"))
.Execute().Should().Pass();

VM.CreateRunCommand("dotnet", "workload", "update")
.Execute().Should().Pass();

GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1");
GetWorkloadVersion().Should().Be(WorkloadSetVersion1);

// Bring latest workload set version back, so installing workload should update to it
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.bak", $"Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.nupkg")
VM.CreateActionGroup($"Enable {WorkloadSetVersion2}",
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.bak", $"Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.nupkg"),
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.bak", $"Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.nupkg"))
.Execute().Should().Pass();

InstallWorkload("aspire", skipManifestUpdate: false);

GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
}

[Fact]
Expand Down

0 comments on commit 73e0054

Please sign in to comment.