Skip to content

Commit 73e0054

Browse files
authored
Workload VM test improvements (#42021)
2 parents 4f75e80 + 16061ef commit 73e0054

File tree

2 files changed

+79
-41
lines changed

2 files changed

+79
-41
lines changed

src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,11 @@ protected void InstallSdk(bool deployStage2 = true)
6666
.Should()
6767
.Pass();
6868

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

81-
VM.CreateActionGroup($"Install SDK {SdkInstallerVersion}",
82-
[
83-
VM.CreateRunCommand($@"c:\SdkTesting\{SdkInstallerFileName}", "/quiet"),
84-
..runtimeInstallers.Select(i => VM.CreateRunCommand($@"c:\SdkTesting\{i}", "/quiet"))
85-
])
86-
.Execute()
87-
.Should()
88-
.Pass();
73+
8974

9075
if (deployStage2)
9176
{
@@ -109,6 +94,27 @@ protected void DeployStage2Sdk()
10994
return;
11095
}
11196

97+
98+
// Install any runtimes that are in the c:\SdkTesting directory, to support using older baseline SDK versions with a newer stage 2
99+
var sdkTestingDir = VM.GetRemoteDirectory(@"c:\SdkTesting");
100+
List<string> runtimeInstallers = new List<string>();
101+
string installerPrefix = "dotnet-runtime-";
102+
string installerSuffix = "-win-x64.exe";
103+
foreach (var file in sdkTestingDir.Files.Select(Path.GetFileName))
104+
{
105+
if (file.StartsWith(installerPrefix) && file.EndsWith(installerSuffix))
106+
{
107+
runtimeInstallers.Add(file);
108+
}
109+
}
110+
111+
if (runtimeInstallers.Any())
112+
{
113+
VM.CreateActionGroup($"Install .NET runtime(s)",
114+
runtimeInstallers.Select(i => VM.CreateRunCommand($@"c:\SdkTesting\{i}", "/quiet")).ToArray())
115+
.Execute().Should().Pass();
116+
}
117+
112118
var result = VM.CreateRunCommand("dotnet", "--version")
113119
.WithIsReadOnly(true)
114120
.Execute();

src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Text;
9+
using System.Text.Json;
910
using System.Threading.Tasks;
1011
using Microsoft.DotNet.MsiInstallerTests.Framework;
1112
using Microsoft.NET.Sdk.WorkloadManifestReader;
@@ -17,8 +18,24 @@ public class WorkloadSetTests : VMTestBase
1718
{
1819
readonly string SdkTestingDirectory = @"C:\SdkTesting";
1920

21+
22+
Lazy<Dictionary<string, string>> _testWorkloadSetVersions;
23+
string WorkloadSetVersion1 => _testWorkloadSetVersions.Value.GetValueOrDefault("version1", "8.0.300-preview.0.24178.1");
24+
string WorkloadSetVersion2 => _testWorkloadSetVersions.Value.GetValueOrDefault("version2", "8.0.300-preview.0.24217.2");
25+
string WorkloadSetPreviousBandVersion => _testWorkloadSetVersions.Value.GetValueOrDefault("previousbandversion", "8.0.204");
26+
2027
public WorkloadSetTests(ITestOutputHelper log) : base(log)
2128
{
29+
_testWorkloadSetVersions = new Lazy<Dictionary<string, string>>(() =>
30+
{
31+
var versionsFile = VM.GetRemoteFile(@"c:\SdkTesting\workloadsets\testworkloadsetversions.json");
32+
if (!versionsFile.Exists)
33+
{
34+
return new Dictionary<string, string>();
35+
}
36+
37+
return JsonSerializer.Deserialize<Dictionary<string, string>>(versionsFile.ReadAllText());
38+
});
2239
}
2340

2441
[Fact]
@@ -91,7 +108,7 @@ public void UpdateWithWorkloadSets()
91108

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

94-
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
111+
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
95112
}
96113

97114
[Fact]
@@ -113,10 +130,19 @@ public void UpdateInWorkloadSetModeWithNoAvailableWorkloadSet()
113130
GetWorkloadVersion().Should().Be(updatedWorkloadVersion);
114131
}
115132

116-
[Theory]
117-
[InlineData("8.0.300-preview.0.24178.1")]
118-
[InlineData("8.0.204")]
119-
public void UpdateToSpecificWorkloadSetVersion(string versionToInstall)
133+
[Fact]
134+
public void UpdateToSpecificWorkloadSetVersion()
135+
{
136+
UpdateToWorkloadSetVersion(WorkloadSetVersion1);
137+
}
138+
139+
[Fact]
140+
public void UpdateToPreviousBandWorkloadSetVersion()
141+
{
142+
UpdateToWorkloadSetVersion(WorkloadSetPreviousBandVersion);
143+
}
144+
145+
private void UpdateToWorkloadSetVersion(string versionToInstall)
120146
{
121147
InstallSdk();
122148

@@ -148,7 +174,7 @@ public void UpdateToSpecificWorkloadSetVersion(string versionToInstall)
148174
.Should()
149175
.Pass();
150176

151-
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
177+
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
152178
}
153179

154180
[Fact]
@@ -207,7 +233,7 @@ public void UpdateToWorkloadSetVersionWithManifestsNotAvailable()
207233

208234
var workloadVersionBeforeUpdate = GetWorkloadVersion();
209235

210-
VM.CreateRunCommand("dotnet", "workload", "update", "--version", @"8.0.300-preview.0.24217.2", "--source", @"c:\SdkTesting\workloadsets")
236+
VM.CreateRunCommand("dotnet", "workload", "update", "--version", WorkloadSetVersion2, "--source", @"c:\SdkTesting\workloadsets")
211237
.Execute()
212238
.Should()
213239
.Fail();
@@ -225,7 +251,7 @@ void SetupWorkloadSetInGlobalJson(out WorkloadSet originalRollback)
225251
{
226252
InstallSdk();
227253

228-
var versionToUpdateTo = "8.0.300-preview.0.24217.2";
254+
var versionToUpdateTo = WorkloadSetVersion2;
229255

230256
string originalVersion = GetWorkloadVersion();
231257

@@ -286,7 +312,7 @@ public void InstallWithVersionAndSkipManifestUpdate()
286312
{
287313
InstallSdk();
288314

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

302328
string originalVersion = GetWorkloadVersion();
303-
originalVersion.Should().NotBe("8.0.300-preview.0.24178.1");
329+
originalVersion.Should().NotBe(WorkloadSetVersion1);
304330

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

308-
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1");
334+
GetWorkloadVersion().Should().Be(WorkloadSetVersion1);
309335

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

313-
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
339+
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
314340
}
315341

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

323349
string originalVersion = GetWorkloadVersion();
324-
originalVersion.Should().NotBe("8.0.300-preview.0.24178.1");
350+
originalVersion.Should().NotBe(WorkloadSetVersion1);
325351

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

329-
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1");
355+
GetWorkloadVersion().Should().Be(WorkloadSetVersion1);
330356

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

335-
GetWorkloadVersion(SdkTestingDirectory).Should().Be("8.0.300-preview.0.24217.2");
361+
GetWorkloadVersion(SdkTestingDirectory).Should().Be(WorkloadSetVersion2);
336362

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

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

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

375+
var packageVersion = WorkloadSet.WorkloadSetVersionToWorkloadSetPackageVersion(WorkloadSetVersion2, out var sdkFeatureBand);
376+
349377
// Rename latest workload set so it won't be installed
350-
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")
378+
VM.CreateActionGroup($"Disable {WorkloadSetVersion2}",
379+
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.nupkg", $"Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.bak"),
380+
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.nupkg", $"Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.bak"))
351381
.Execute().Should().Pass();
352382

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

356-
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1");
386+
GetWorkloadVersion().Should().Be(WorkloadSetVersion1);
357387

358388
// Bring latest workload set version back, so installing workload should update to it
359-
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")
389+
VM.CreateActionGroup($"Enable {WorkloadSetVersion2}",
390+
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.bak", $"Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.nupkg"),
391+
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.bak", $"Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.nupkg"))
360392
.Execute().Should().Pass();
361393

362394
InstallWorkload("aspire", skipManifestUpdate: false);
363395

364-
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
396+
GetWorkloadVersion().Should().Be(WorkloadSetVersion2);
365397
}
366398

367399
[Fact]

0 commit comments

Comments
 (0)