dotnet-installer/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs
Andrew Stanton-Nurse ef0ca39da1 Memory usage improvements in build (#2626)
* Use a WorkspaceContext in dotnet-build to cache project data across
multiple compilations in a single build action
* Dramatically reduce string and object duplication by introducing a
"Symbol Table" that shares instances of NuGetVersion, NuGetFramework,
VersionRange and string across multiple lock-file parses

Test Results:
* Testing was done by compiling Microsoft.AspNetCore.Mvc (and it's
dependencies) and taking memory snapshots after each compilation in
dotMemory
* We used to allocate ~3MB and deallocate ~2.5MB on EACH compilation in
a single build action. This has been reduced to ~120KB
allocated/deallocated
* After introducing WorkspaceContext, total memory usage spiked from 6MB
across the whole build action to about 13MB, introducing the symbol
table dropped it back to about 5-6MB.
2016-04-22 15:01:56 -07:00

97 lines
4 KiB
C#

using System.Linq;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Resolution;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using NuGet.Versioning;
using Xunit;
namespace Microsoft.DotNet.ProjectModel.Tests
{
public class PackageDependencyProviderTests : TestBase
{
[Fact]
public void GetDescriptionShouldNotModifyTarget()
{
var provider = new PackageDependencyProvider("/foo/packages", new FrameworkReferenceResolver("/foo/references"));
var package = new LockFilePackageLibrary();
package.Name = "Something";
package.Version = NuGetVersion.Parse("1.0.0");
package.Files.Add("lib/dotnet/_._");
package.Files.Add("runtimes/any/native/Microsoft.CSharp.CurrentVersion.targets");
var target = new LockFileTargetLibrary();
target.Name = "Something";
target.Version = package.Version;
target.RuntimeAssemblies.Add("lib/dotnet/_._");
target.CompileTimeAssemblies.Add("lib/dotnet/_._");
target.NativeLibraries.Add("runtimes/any/native/Microsoft.CSharp.CurrentVersion.targets");
var p1 = provider.GetDescription(NuGetFramework.Parse("netcoreapp1.0"), package, target);
var p2 = provider.GetDescription(NuGetFramework.Parse("netcoreapp1.0"), package, target);
Assert.True(p1.Compatible);
Assert.True(p2.Compatible);
Assert.Empty(p1.CompileTimeAssemblies);
Assert.Empty(p1.RuntimeAssemblies);
Assert.Empty(p2.CompileTimeAssemblies);
Assert.Empty(p2.RuntimeAssemblies);
}
[Theory]
[InlineData("TestMscorlibReference", true)]
[InlineData("TestMscorlibReference", false)]
[InlineData("TestMicrosoftCSharpReference", true)]
[InlineData("TestMicrosoftCSharpReference", false)]
[InlineData("TestSystemReference", true)]
[InlineData("TestSystemReference", false)]
[InlineData("TestSystemCoreReference", true)]
[InlineData("TestSystemCoreReference", false)]
public void TestDuplicateDefaultDesktopReferences(string sampleName, bool withLockFile)
{
var instance = TestAssetsManager.CreateTestInstance(sampleName);
if (withLockFile)
{
instance = instance.WithLockFiles();
}
var context = new ProjectContextBuilder().WithProjectDirectory(instance.TestRoot)
.WithTargetFramework("net451")
.Build();
Assert.Equal(4, context.RootProject.Dependencies.Count());
}
[Fact]
public void NoDuplicateReferencesWhenFrameworkMissing()
{
var instance = TestAssetsManager.CreateTestInstance("TestMicrosoftCSharpReferenceMissingFramework")
.WithLockFiles();
var context = new ProjectContextBuilder().WithProjectDirectory(instance.TestRoot)
.WithTargetFramework("net99")
.Build();
// Will fail with dupes if any
context.LibraryManager.GetLibraries().ToDictionary(l => l.Identity.Name);
}
[Fact]
public void NetCore50ShouldNotResolveFrameworkAssemblies()
{
var instance = TestAssetsManager.CreateTestInstance("TestMicrosoftCSharpReferenceMissingFramework")
.WithLockFiles();
var context = new ProjectContextBuilder().WithProjectDirectory(instance.TestRoot)
.WithTargetFramework("netcore50")
.Build();
var diagnostics = context.LibraryManager.GetAllDiagnostics();
Assert.False(diagnostics.Any(d => d.ErrorCode == ErrorCodes.DOTNET1011));
}
}
}