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

Improve SystemTests execution time #253

Merged
merged 11 commits into from
Oct 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Bug fixes:

*Contributors of this release (in alphabetical order):*
*Contributors of this release (in alphabetical order): @obligaron*

# v2.1.1 - 2024-10-08

Expand Down
67 changes: 67 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,71 @@
</ItemGroup>
<Copy SourceFiles="@(GeneratedNupkgs)" DestinationFolder="$(MSBuildThisFileDirectory)GeneratedNuGetPackages\$(Configuration)" />
</Target>

<UsingTask
TaskName="ReqnrollClearNuGetCache"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<NuGetCacheDirectory ParameterType="System.String" Required="true" />
<EnsureNugetCacheCleared ParameterType="System.String" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
string TmpDirectory = NuGetCacheDirectory + "-remove";

Log.LogMessage("Cleaning local nuget cache " + NuGetCacheDirectory);

if (Directory.Exists(TmpDirectory))
{
try
{
Directory.Delete(TmpDirectory, true);
}
catch
{
Log.LogError("Can't start cleaning NuGet Cache Directory, deleting temporary directory failed: " + NuGetCacheDirectory);
}
}
if (Directory.Exists(NuGetCacheDirectory))
{
try
{
// If a file is locked, calling Directory.Delete can result in half-removed directories.
// This is bad for nuget caches, as dotnet restore may fail in these cases.
// That's why we first move the directory (which is only possible if no file is locked in the directory) and then delete the renamed directory.
Directory.Move(NuGetCacheDirectory, TmpDirectory);
}
catch (Exception ex)
{
if (EnsureNugetCacheCleared != "false")
Log.LogError("Can't clean NuGet Cache Directory " + NuGetCacheDirectory + ". Set REQNROLL_ENSURE_NUGET_CACHE_CLEARED to false to handle this error as a warning. " + ex.Message);
else
Log.LogWarning("Can't clean NuGet Cache Directory " + NuGetCacheDirectory);
}
}
if (Directory.Exists(TmpDirectory))
{
try
{
Directory.Delete(TmpDirectory, true);
}
catch
{
Log.LogWarning("Can't finish cleaning NuGet Cache Directory, deleting temporary directory failed: " + NuGetCacheDirectory);
}
}
]]>
</Code>
</Task>
</UsingTask>

<Target Name="DeleteLocalNuGetCache" BeforeTargets="Pack" Condition="$(VersionSuffix)=='local'">
<!--Clears the NuGet cache manually until https://github.com/NuGet/Home/issues/5713 is fixed.-->
<!--Implementation based on https://www.nyckel.com/blog/nuget-packages/.-->
<ReqnrollClearNuGetCache NuGetCacheDirectory="$(NugetPackageRoot)/$(PackageId.ToLower())/$(VersionPrefix)-$(VersionSuffix)" EnsureNugetCacheCleared="$(REQNROLL_ENSURE_NUGET_CACHE_CLEARED)"/>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>

<PackageId>Reqnroll.Autofac</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>$(MSBuildThisFileDirectory)Reqnroll.Autofac.nuspec</NuspecFile>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

<PackageId>Reqnroll.ExternalData</PackageId>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<AssemblyOriginatorKeyFile>$(Reqnroll_KeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>
<PackageId>Reqnroll.MsTest</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>

<PackageId>Reqnroll.Microsoft.Extensions.DependencyInjection</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>$(MSBuildThisFileDirectory)Reqnroll.Microsoft.Extensions.DependencyInjection.nuspec</NuspecFile>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<AssemblyOriginatorKeyFile>$(Reqnroll_KeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>
<PackageId>Reqnroll.NUnit</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<AssemblyOriginatorKeyFile>$(Reqnroll_KeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>
<PackageId>Reqnroll.SpecFlowCompatibility</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>

<PackageId>Reqnroll.Verify</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>$(MSBuildThisFileDirectory)Reqnroll.Verify.nuspec</NuspecFile>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>

<PackageId>Reqnroll.Windsor</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>$(MSBuildThisFileDirectory)Reqnroll.Windsor.nuspec</NuspecFile>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<SignAssembly>$(Reqnroll_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(Reqnroll_PublicSign)</PublicSign>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>Reqnroll.xUnit</PackageId>
</PropertyGroup>
<ItemGroup>
<Compile Remove="build\**\*" />
Expand Down
2 changes: 1 addition & 1 deletion Tests/Reqnroll.SystemTests/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)]
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
Original file line number Diff line number Diff line change
Expand Up @@ -279,38 +279,6 @@ public void CreateEmptyCSharpProjectInNewFormat()
});
}

[SkippableFact]
public void CreateEmptyCSharpCore3_1ProjectInNewFormat()
{
RunSkippableTest(() =>
{
var (solution, project, solutionFolder) = CreateEmptySolutionAndProject(ProjectFormat.New, ProgrammingLanguage.CSharp, TargetFramework.Netcoreapp31);

CreateSolutionWriter().WriteToFileSystem(solution, solutionFolder);

string projectFileContent = GetProjectFileContent(solutionFolder, project);

projectFileContent.Should()
.Contain("<Project Sdk=\"Microsoft.NET.Sdk\">\r\n <PropertyGroup>\r\n <TargetFramework>netcoreapp3.1</TargetFramework>\r\n </PropertyGroup>\r\n</Project>");
});
}

[SkippableFact]
public void CreateEmptyCSharpNet50ProjectInNewFormat()
{
RunSkippableTest(() =>
{
var (solution, project, solutionFolder) = CreateEmptySolutionAndProject(ProjectFormat.New, ProgrammingLanguage.CSharp73, TargetFramework.Net50);

CreateSolutionWriter().WriteToFileSystem(solution, solutionFolder);

string projectFileContent = GetProjectFileContent(solutionFolder, project);

projectFileContent.Should()
.Contain("<Project Sdk=\"Microsoft.NET.Sdk\">\r\n <PropertyGroup>\r\n <TargetFramework>net5.0</TargetFramework>\r\n <LangVersion>7.3</LangVersion>\r\n </PropertyGroup>\r\n</Project>");
});
}

[SkippableFact]
public void CreateEmptyCSharpNet60ProjectInNewFormat()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ConfigurationDriver
public string VSTestPath => GetConfigSetting("vstestPath", "Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow");
public string MsBuildPath => GetConfigSetting(nameof(MsBuildPath));
public bool PipelineMode => GetConfigSwitch(nameof(PipelineMode));
public bool PerRunNuGetPackages => GetConfigSwitch(nameof(PerRunNuGetPackages));
public string GlobalNuGetPackages => GetConfigSetting(nameof(GlobalNuGetPackages));

public bool GetConfigSwitch(string key, bool defaultValue = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override string GetWorkingDirectory()

protected override string BuildArguments()
{
var arguments = AddArgument($"new {_templateName}", "-o", "\"" + _folder + "\"");
var arguments = AddArgument($"new {_templateName} --no-update-check", "-o", "\"" + _folder + "\"");
arguments = AddArgument(
arguments,
"-lang",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public string Reqnroll
public virtual string FolderToSaveGeneratedSolutions => Path.Combine(_configurationDriver.TempFolderPath, _configurationDriver.TestProjectFolderName);

public virtual string RunUniqueFolderToSaveGeneratedSolutions => Path.Combine(FolderToSaveGeneratedSolutions, _artifactNamingConvention.GetRunName(UniqueRunId));
public virtual string GlobalNuGetPackages => _configurationDriver.PipelineMode ? SystemGlobalNuGetPackages : _configurationDriver.GlobalNuGetPackages ?? Path.Combine(RunUniqueFolderToSaveGeneratedSolutions, ".nuget");
public virtual string GlobalNuGetPackages => (_configurationDriver.PipelineMode || !_configurationDriver.PerRunNuGetPackages || _configurationDriver.GlobalNuGetPackages != null)
? SystemGlobalNuGetPackages : _configurationDriver.GlobalNuGetPackages ?? Path.Combine(RunUniqueFolderToSaveGeneratedSolutions, ".nuget");
public bool IsGlobalPackagesCustomized => GlobalNuGetPackages != SystemGlobalNuGetPackages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Reqnroll.TestProjectGenerator.Helpers;
public class FolderCleaner
{
private const int MaxTestRunAgeMinutes = 60;
private const int MaxTestRunsToKeep = 4;
private const int MaxTestRunsToKeep = 6;

private static int _oldFoldersCleaned = 0;
private readonly Folders _folders;
Expand Down