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

Build compatibility matrix tests faster #3884

Merged
merged 8 commits into from
Jul 22, 2022
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ ehthumbs.db
*.zip
/src/package/sign/sign.nuget.targets

test/GeneratedTestAssets/

# ===========================
# Localized resx files
# ===========================
Expand Down
290 changes: 209 additions & 81 deletions scripts/build.ps1

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions scripts/common.lib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,32 @@ function Start-InlineProcess {
$process.Dispose()
}
}

Add-Type -TypeDefinition @"
public static class Hash {
public static string GetHash(string value)
{
unchecked
{
ulong hash = 23;
foreach (char ch in value)
{
hash = hash * 31;
hash += ch;
}

return string.Format("{0:X}", hash);
}
}
}
"@

function Get-Hash {
param (
[Parameter(Mandatory)]
[string]$Value
)

# PowerShell does not have unchecked keyword, so we can't do unchecked math easily.
[Hash]::GetHash($Value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected static void SetTestEnvironment(IntegrationTestEnvironment testEnvironm
{
testEnvironment.VSTestConsoleInfo = runnerInfo.VSTestConsoleInfo;
// The order here matters, it changes how the resulting path is built when we resolve test dlls and other assets.
testEnvironment.DllInfos = new[] { runnerInfo.AdapterInfo, runnerInfo.TestHostInfo }.Where(d => d != null).Select(x => x!).ToList();
testEnvironment.DllInfos = new[] { runnerInfo.TestHostInfo, runnerInfo.AdapterInfo }.Where(d => d != null).Select(x => x!).ToList();
testEnvironment.DebugInfo = runnerInfo.DebugInfo;

testEnvironment.RunnerFramework = runnerInfo.RunnerFramework!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,6 @@ private void AddRow(List<RunnerInfo> dataRows, string batch,
RunnerInfo runnerInfo = GetRunnerInfo(batch, runnerFramework, hostFramework, inIsolation);
runnerInfo.DebugInfo = GetDebugInfo();
runnerInfo.VSTestConsoleInfo = GetVSTestConsoleInfo(runnerVersion, runnerInfo);

// The order in which we add them matters. We end up both modifying the same path
// and adding to it. So the first one added will be later in the path. E.g.:
// Adding testSdk first:
// C:\p\vstest\test\TestAssets\MSTestProject1\bin\MSTestLatestPreview-2.2.9-preview-20220210-07\NETTestSdkLatest-17.2.0-dev\Debug\net462\MSTestProject1.dll
// versus adding testSdk second:
// C:\p\vstest\test\TestAssets\MSTestProject1\bin\NETTestSdkLatest-17.2.0-dev\MSTestLatestPreview-2.2.9-preview-20220210-07\Debug\net462\MSTestProject1.dll
runnerInfo.TestHostInfo = GetNetTestSdkInfo(hostVersion);
runnerInfo.AdapterInfo = GetMSTestInfo(adapterVersion);
dataRows.Add(runnerInfo);
Expand Down Expand Up @@ -329,16 +322,15 @@ private static DllInfo GetMSTestInfo(string msTestVersion)
// This way it throws in the body of the test which has better error reporting than throwing in the data source.
XmlNode? node = depsXml.DocumentElement?.SelectSingleNode($"PropertyGroup/MSTestFramework{msTestVersion}Version");
var version = node?.InnerText.Replace("[", "").Replace("]", "");
var slash = Path.DirectorySeparatorChar;
var versionSpecificBinPath = $"{slash}bin{slash}MSTest{msTestVersion}-{version}{slash}";
var versionSpecificPath = $"MSTest{msTestVersion}-{version}";

return new DllInfo
{
Name = "MSTest",
PropertyName = "MSTest",
VersionType = msTestVersion,
Version = version,
Path = versionSpecificBinPath,
Path = versionSpecificPath,
};
}

Expand Down Expand Up @@ -391,7 +383,6 @@ private static NetTestSdkInfo GetNetTestSdkInfo(string testhostVersionType)

// When version is Latest, we built it locally, but it gets restored into our nuget cache on build
// same as other versions, we just need to grab the version from a different property.

var propertyName = testhostVersionType == AcceptanceTestBase.LATEST
? "NETTestSdkVersion"
: $"VSTestConsole{testhostVersionType}Version";
Expand All @@ -402,14 +393,13 @@ private static NetTestSdkInfo GetNetTestSdkInfo(string testhostVersionType)
// We use the VSTestConsole properties to figure out testhost version, for now.
XmlNode? node = depsXml.DocumentElement?.SelectSingleNode($"PropertyGroup/{propertyName}");
var version = node?.InnerText.Replace("[", "").Replace("]", "");
var slash = Path.DirectorySeparatorChar;
var versionSpecificBinPath = $"{slash}bin{slash}NETTestSdk{testhostVersionType}-{version}{slash}";
var versionSpecificPath = $"NETTestSdk{testhostVersionType}-{version}";

return new NetTestSdkInfo
{
VersionType = testhostVersionType,
Version = version,
Path = versionSpecificBinPath
Path = versionSpecificPath
};
}

Expand Down
11 changes: 0 additions & 11 deletions test/Microsoft.TestPlatform.TestUtilities/DllInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,4 @@ public class DllInfo
public string? Path { get; set; }

public override string ToString() => $" {Name} = {Version} [{VersionType}]";

public string UpdatePath(string path)
{
// Version is not directly used, below, but if it is not populated the path will be incorrect.
// We don't want to throw when creating SourcePathInfo because that is happening too early, and has worse error reporting.
if (Version == null)
throw new InvalidOperationException($"Version was not correctly populated from TestPlatform.Dependencies.props, review that there is entry for {PropertyName}{VersionType}Version.");

// TODO: replacing in the result string is lame, but I am not going to fight 20 GetAssetFullPath method overloads right now
return path.Replace($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}", Path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.Common;
Expand Down Expand Up @@ -216,17 +217,32 @@ public string GetTestAsset(string assetName, string targetFramework)
// Update the path to be taken from the compatibility matrix instead of from the root folder.
if (DllInfos.Count > 0)
{
foreach (var dllInfo in DllInfos)
{
assetPath = dllInfo.UpdatePath(assetPath);
}
// The path is really ugly: S:\p\vstest3\test\GeneratedTestAssets\NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0--MSTestProject2\bin\Debug\net462\MSTestProject2-NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0.dll
// And we need to hash the versions in it to get shorter path as well.
var versions = string.Join("--", DllInfos.Select(d => d.Path));
var versionsHash = Hash(versions);
assetPath = Path.Combine(TestAssetsPath, "..", "GeneratedTestAssets", $"{simpleAssetName}--{versionsHash}", "bin", BuildConfiguration, targetFramework, $"{simpleAssetName}--{versionsHash}.dll");
}

Assert.IsTrue(File.Exists(assetPath), "GetTestAsset: Path not found: \"{0}\". Most likely you need to build using build.cmd -s PrepareAcceptanceTests.", assetPath);

// If you are thinking about wrapping the path in double quotes here,
// then don't. File.Exist cannot handle quoted paths, and we use it in a lot of places.
return assetPath;

static string Hash(string value)
{
unchecked
{
long hash = 23;
foreach (char ch in value)
{
hash = hash * 31 + ch;
}

return $"{hash:X}";
}
}
}

/// <summary>
Expand Down
14 changes: 0 additions & 14 deletions test/TestAssets/NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<clear />
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" />
<add key="dotnet3.1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
<add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
<add key="dotnet5" value="https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet5/nuget/v3/index.json" />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="vs-impl" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json" />
<add key="vssdk" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json" />
</packageSources>
<fallbackPackageFolders>
<clear />
</fallbackPackageFolders>
Expand Down