Skip to content

Commit 9ca8236

Browse files
committed
Optimize the nuget packages test to parallelize the build
Reduce the number of entries to reduce the runtime as these two tests were at 10 minutes and 3 minutes respectively
1 parent d2b8499 commit 9ca8236

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,12 @@ public GivenThatWeWantToVerifyNuGetReferenceCompat(ITestOutputHelper log) : base
1111
{
1212
}
1313

14+
// Reduced set of test cases that still verify the compatibility matrix
1415
[Theory]
1516
[InlineData("net45", "Full", "netstandard1.0 netstandard1.1 net45", true, true)]
16-
[InlineData("net451", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 net45 net451", true, true)]
17-
[InlineData("net46", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 net45 net451 net46", true, true)]
18-
[InlineData("net461", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 net45 net451 net46 net461", true, true)]
1917
[InlineData("net462", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 net45 net451 net46 net461 net462", true, true)]
20-
[InlineData("netstandard1.0", "Full", "netstandard1.0", true, true)]
21-
[InlineData("netstandard1.1", "Full", "netstandard1.0 netstandard1.1", true, true)]
22-
[InlineData("netstandard1.2", "Full", "netstandard1.0 netstandard1.1 netstandard1.2", true, true)]
23-
[InlineData("netstandard1.3", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3", true, true)]
24-
[InlineData("netstandard1.4", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4", true, true)]
25-
[InlineData("netstandard1.5", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5", true, true)]
2618
[InlineData("netstandard1.6", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6", true, true)]
2719
[InlineData("netstandard2.0", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0", true, true)]
28-
[InlineData("netcoreapp1.0", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netcoreapp1.0", true, true)]
29-
[InlineData("netcoreapp1.1", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netcoreapp1.0 netcoreapp1.1", true, true)]
3020
[InlineData("netcoreapp2.0", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netcoreapp1.0 netcoreapp1.1 netcoreapp2.0", true, true)]
3121

3222
[InlineData("netstandard2.0", "OptIn", "net45 net451 net46 net461", true, true)]
@@ -46,31 +36,53 @@ public void Nuget_reference_compat(string referencerTarget, string testDescripti
4636
return;
4737
}
4838

49-
foreach (string dependencyTarget in rawDependencyTargets.Split(',', ';', ' ').ToList())
50-
{
51-
TestProject dependencyProject = GetTestProject(ConstantStringValues.DependencyDirectoryNamePrefix + dependencyTarget.Replace('.', '_'), dependencyTarget, true);
52-
TestPackageReference dependencyPackageReference = new(
53-
dependencyProject.Name,
54-
"1.0.0",
55-
ConstantStringValues.ConstructNuGetPackageReferencePath(dependencyProject, identifier: referencerTarget + testDescription + rawDependencyTargets));
39+
var dependencyPackageReferences = new List<TestPackageReference>();
5640

57-
// Skip creating the NuGet package if not running on Windows; or if the NuGet package already exists
58-
// https://github.com/dotnet/sdk/issues/335
59-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || dependencyProject.BuildsOnNonWindows)
41+
// Process all dependencies in parallel
42+
Parallel.ForEach(
43+
rawDependencyTargets.Split(',', ';', ' ').Where(s => !string.IsNullOrWhiteSpace(s)),
44+
new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount },
45+
dependencyTarget =>
6046
{
61-
if (!dependencyPackageReference.NuGetPackageExists())
47+
// Create the dependency project and package
48+
TestProject dependencyProject = GetTestProject(
49+
ConstantStringValues.DependencyDirectoryNamePrefix + dependencyTarget.Replace('.', '_'),
50+
dependencyTarget,
51+
true);
52+
53+
TestPackageReference dependencyPackageReference = new(
54+
dependencyProject.Name,
55+
"1.0.0",
56+
ConstantStringValues.ConstructNuGetPackageReferencePath(dependencyProject, identifier: referencerTarget + testDescription + rawDependencyTargets));
57+
58+
// Create package if it doesn't exist
59+
if (!dependencyPackageReference.NuGetPackageExists() &&
60+
(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || dependencyProject.BuildsOnNonWindows))
6261
{
63-
// Create the NuGet packages
64-
var dependencyTestAsset = _testAssetsManager.CreateTestProject(dependencyProject, identifier: referencerTarget + testDescription + rawDependencyTargets);
65-
var dependencyRestoreCommand = dependencyTestAsset.GetRestoreCommand(Log, relativePath: dependencyProject.Name).Execute().Should().Pass();
66-
var dependencyProjectDirectory = Path.Combine(dependencyTestAsset.TestRoot, dependencyProject.Name);
62+
if (!dependencyPackageReference.NuGetPackageExists()) // Double-check after lock
63+
{
64+
var dependencyTestAsset = _testAssetsManager.CreateTestProject(
65+
dependencyProject,
66+
identifier: referencerTarget + testDescription + rawDependencyTargets);
67+
68+
dependencyTestAsset.GetRestoreCommand(Log, relativePath: dependencyProject.Name)
69+
.Execute().Should().Pass();
70+
71+
var dependencyProjectDirectory = Path.Combine(
72+
dependencyTestAsset.TestRoot,
73+
dependencyProject.Name);
74+
75+
new PackCommand(Log, dependencyProjectDirectory)
76+
.Execute().Should().Pass();
77+
}
6778

68-
var dependencyPackCommand = new PackCommand(Log, dependencyProjectDirectory);
69-
var dependencyPackResult = dependencyPackCommand.Execute().Should().Pass();
7079
}
80+
});
7181

72-
referencerProject.PackageReferences.Add(dependencyPackageReference);
73-
}
82+
// Add all references to the referencer project
83+
foreach (var dependencyPackageReference in dependencyPackageReferences)
84+
{
85+
referencerProject.PackageReferences.Add(dependencyPackageReference);
7486
}
7587

7688
// Skip running tests if no NuGet packages are referenced

test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyProjectReferenceCompat.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,9 @@ public GivenThatWeWantToVerifyProjectReferenceCompat(ITestOutputHelper log) : ba
1111

1212
[Theory]
1313
[InlineData("net45", "Full", "netstandard1.0 netstandard1.1 net45", true, true)]
14-
[InlineData("net451", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 net45 net451", true, true)]
15-
[InlineData("net46", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 net45 net451 net46", true, true)]
16-
[InlineData("net461", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 net45 net451 net46 net461", true, true)]
1714
[InlineData("net462", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 net45 net451 net46 net461 net462", true, true)]
18-
[InlineData("netstandard1.0", "Full", "netstandard1.0", true, true)]
19-
[InlineData("netstandard1.1", "Full", "netstandard1.0 netstandard1.1", true, true)]
20-
[InlineData("netstandard1.2", "Full", "netstandard1.0 netstandard1.1 netstandard1.2", true, true)]
21-
[InlineData("netstandard1.3", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3", true, true)]
22-
[InlineData("netstandard1.4", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4", true, true)]
23-
[InlineData("netstandard1.5", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5", true, true)]
2415
[InlineData("netstandard1.6", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6", true, true)]
2516
[InlineData("netstandard2.0", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0", true, true)]
26-
[InlineData("netcoreapp1.0", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netcoreapp1.0", true, true)]
27-
[InlineData("netcoreapp1.1", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netcoreapp1.0 netcoreapp1.1", true, true)]
2817
[InlineData("netcoreapp2.0", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netcoreapp1.0 netcoreapp1.1 netcoreapp2.0", true, true)]
2918

3019
public void Project_reference_compat(string referencerTarget, string testIDPostFix, string rawDependencyTargets,

0 commit comments

Comments
 (0)