Skip to content
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
7 changes: 2 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
<!-- It also needs to be added to nuspec manually (for projects that use nuspec) so that the new version flows to consumers -->
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildCachePackageEnabled)' == 'true'" Label="Build dependencies">
<MSBuildCachePackageName Condition="'$(TF_BUILD)' != ''">Microsoft.MSBuildCache.AzurePipelines</MSBuildCachePackageName>
<MSBuildCachePackageName Condition="'$(MSBuildCachePackageName)' == ''">Microsoft.MSBuildCache.Local</MSBuildCachePackageName>
<MSBuildCachePackageVersion>0.1.328-preview</MSBuildCachePackageVersion>
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)eng\MSBuildCache.props"
Condition="'$(MSBuildCachePackageEnabled)' == 'true'" />
<ItemGroup Condition="'$(MSBuildCachePackageEnabled)' == 'true'" Label="Build dependencies">
<GlobalPackageReference Include="$(MSBuildCachePackageName)" Version="$(MSBuildCachePackageVersion)" />
<GlobalPackageReference Include="Microsoft.MSBuildCache.SharedCompilation" Version="$(MSBuildCachePackageVersion)" />
Expand Down
11 changes: 9 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ stages:
jobs:
- job: Windows
displayName: Windows
timeoutInMinutes: 90
# The Release writer must survive the same completely cold generated-fixture builds as
# validation; otherwise broad invalidations can time out before publishing remote entries.
timeoutInMinutes: 120
pool:
name: NetCore-Public
demands: ImageOverride -equals windows.vs2026preview.scout.amd64.open
Expand Down Expand Up @@ -291,6 +293,7 @@ stages:
# Enable only after the prerequisites in docs/affected-test-selection.md are satisfied.
enableAffectedTests: false
affectedTestsMode: collect
acceptanceTestCacheMode: write

- task: PublishBuildArtifacts@1
displayName: 'Publish cache seed build binlogs'
Expand Down Expand Up @@ -431,7 +434,10 @@ stages:
# XML-documentation-only PRs use it only for compiler and package validation. Debug remains
# skippable for samples-only and XML-doc-only PRs.
condition: and(succeededOrFailed(), ne(dependencies.DetectChanges.outputs['detect.infrastructureOnly'], 'true'), or(eq(variables._BuildConfig, 'Release'), and(ne(dependencies.DetectChanges.outputs['detect.xmlDocsOnly'], 'true'), ne(dependencies.DetectChanges.outputs['detect.hasProductChanges'], 'false'))))
timeoutInMinutes: 90
# A completely cold acceptance cache builds every generated fixture. Keep enough headroom
# for that bootstrap path; warm PR runs remain substantially faster and the test command
# retains its existing failure semantics.
timeoutInMinutes: 120
pool:
name: NetCore-Public
demands: ImageOverride -equals windows.vs2026preview.scout.amd64.open
Expand Down Expand Up @@ -763,6 +769,7 @@ stages:
# Enable only after the prerequisites in docs/affected-test-selection.md are satisfied.
enableAffectedTests: false
affectedTestsMode: run
acceptanceTestCacheMode: read

# artifacts/TestResults/$(_BuildConfig) only exists once a test step has written into it, and
# PublishBuildArtifacts@1 hard-fails when PathtoPublish does not exist. A job that dies before the
Expand Down
7 changes: 7 additions & 0 deletions eng/MSBuildCache.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<MSBuildCachePackageName Condition="'$(TF_BUILD)' != ''">Microsoft.MSBuildCache.AzurePipelines</MSBuildCachePackageName>
<MSBuildCachePackageName Condition="'$(MSBuildCachePackageName)' == ''">Microsoft.MSBuildCache.Local</MSBuildCachePackageName>
<MSBuildCachePackageVersion>0.1.328-preview</MSBuildCachePackageVersion>
</PropertyGroup>
</Project>
19 changes: 19 additions & 0 deletions eng/pipelines/steps/test-windows-configuration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ parameters:
- name: affectedTestsCacheVersion
type: string
default: v1
- name: acceptanceTestCacheMode
type: string
default: disabled
values:
- disabled
- read
- write

steps:
# Because the build step is using -ci, restore is done in a local .packages directory.
Expand All @@ -32,6 +39,9 @@ steps:
displayName: Test
condition: and(succeeded(), eq(variables._BuildConfig, 'Release'), ne(variables._XmlDocsOnly, 'true'))
env:
TESTFX_ACCEPTANCE_MSBUILD_CACHE_MODE: ${{ parameters.acceptanceTestCacheMode }}
TESTFX_ACCEPTANCE_MSBUILD_CACHE_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCache\$(_BuildConfig)'
TESTFX_ACCEPTANCE_MSBUILD_CACHE_LOG_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCacheLogs\$(_BuildConfig)'
# Secret variables are not automatically exposed to scripts. Fork PR builds do not receive this token,
# so report-azdo history queries no-op there; trusted branch builds exercise them end-to-end.
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
Expand All @@ -58,6 +68,9 @@ steps:
condition: and(succeeded(), eq(variables._BuildConfig, 'Release'), ne(variables._XmlDocsOnly, 'true'))
env:
DOTNET_CLI_ENABLE_AFFECTED_TESTS: 1
TESTFX_ACCEPTANCE_MSBUILD_CACHE_MODE: ${{ parameters.acceptanceTestCacheMode }}
TESTFX_ACCEPTANCE_MSBUILD_CACHE_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCache\$(_BuildConfig)'
TESTFX_ACCEPTANCE_MSBUILD_CACHE_LOG_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCacheLogs\$(_BuildConfig)'
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- ${{ if and(eq(parameters.enableAffectedTests, true), eq(parameters.affectedTestsMode, 'run')) }}:
Expand Down Expand Up @@ -91,6 +104,9 @@ steps:
condition: and(succeeded(), eq(variables._BuildConfig, 'Release'), ne(variables._XmlDocsOnly, 'true'), eq(variables['Build.Reason'], 'PullRequest'), ne(variables['AffectedTestsMapCacheRestored'], 'false'))
env:
DOTNET_CLI_ENABLE_AFFECTED_TESTS: 1
TESTFX_ACCEPTANCE_MSBUILD_CACHE_MODE: ${{ parameters.acceptanceTestCacheMode }}
TESTFX_ACCEPTANCE_MSBUILD_CACHE_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCache\$(_BuildConfig)'
TESTFX_ACCEPTANCE_MSBUILD_CACHE_LOG_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCacheLogs\$(_BuildConfig)'
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

# Scheduled and manual runs keep their full-validation contract. PRs also fall back when the cache is absent or the
Expand All @@ -110,6 +126,9 @@ steps:
displayName: Test (affected-test fallback)
condition: and(succeeded(), eq(variables._BuildConfig, 'Release'), ne(variables._XmlDocsOnly, 'true'), or(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['AffectedTestsMapCacheRestored'], 'false'), ne(variables['AffectedTestsSucceeded'], 'true')))
env:
TESTFX_ACCEPTANCE_MSBUILD_CACHE_MODE: ${{ parameters.acceptanceTestCacheMode }}
TESTFX_ACCEPTANCE_MSBUILD_CACHE_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCache\$(_BuildConfig)'
TESTFX_ACCEPTANCE_MSBUILD_CACHE_LOG_ROOT: '$(Agent.TempDirectory)\AcceptanceMSBuildCacheLogs\$(_BuildConfig)'
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- ${{ if and(eq(parameters.enableAffectedTests, true), eq(parameters.affectedTestsMode, 'disabled')) }}:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public static void AssemblyInitialize(TestContext context)
s_directoryToCleanup = Path.Combine(TempDirectory.TestSuiteDirectory, RandomId.Next());

// Ensure all integration tests restore packages in a centralized place other than the NuGet cache.
// The centralized place also changes between runs (RandomId.Next()) so that re-packaging locally works as expected.
// So, when running Build.cmd -pack, running test, running Build.cmd -pack again, and running test again, the latest
// packages should be picked.
// If we restore to the same place (whether or not it is the machine-wide cache), NuGet will consider restore up-to-date and
// will use stale packages.
string nugetCache = Path.Combine(s_directoryToCleanup, ".packages");
// Local runs keep changing this location so rebuilding same-version development packages cannot
// reuse stale contents. Cached CI fixture builds need one stable package root for portable cache
// fingerprints, and nested acceptance commands must use that same populated root.
string? acceptanceCacheRoot = Environment.GetEnvironmentVariable("TESTFX_ACCEPTANCE_MSBUILD_CACHE_ROOT");
string? acceptanceCacheMode = Environment.GetEnvironmentVariable("TESTFX_ACCEPTANCE_MSBUILD_CACHE_MODE");
string? stableNuGetCache = acceptanceCacheMode is "read" or "write"
&& !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("SYSTEM_ACCESSTOKEN"))
&& acceptanceCacheRoot is { Length: > 0 }
? Path.Combine(acceptanceCacheRoot, "NuGetPackages")
: null;
string nugetCache = stableNuGetCache ?? Path.Combine(s_directoryToCleanup, ".packages");
Directory.CreateDirectory(nugetCache);
Environment.SetEnvironmentVariable("NUGET_PACKAGES", nugetCache);
}
Expand Down
91 changes: 51 additions & 40 deletions test/Utilities/Microsoft.Testing.TestInfrastructure/DotnetCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Microsoft.Testing.TestInfrastructure;

public static class DotnetCli
{
internal readonly struct CommandSlot : IDisposable
{
public void Dispose() => s_maxOutstandingCommands_semaphore.Release();
}

private static readonly string[] CodeCoverageEnvironmentVariables =
[
"MicrosoftInstrumentationEngine_ConfigPath32_VanguardInstrumentationProfiler",
Expand Down Expand Up @@ -56,57 +61,63 @@ public static async Task<DotnetMuxerResult> RunAsync(
[CallerMemberName] string callerMemberName = "",
CancellationToken cancellationToken = default)
{
await s_maxOutstandingCommands_semaphore.WaitAsync(cancellationToken);
try
using CommandSlot commandSlot = await AcquireCommandSlotAsync(cancellationToken);
environmentVariables = CreateEnvironmentVariables(environmentVariables, disableTelemetry, disableCodeCoverage);

string extraArgs = warnAsError ? " -p:MSBuildTreatWarningsAsErrors=true -p:TreatWarningsAsErrors=true" : string.Empty;
extraArgs += suppressPreviewDotNetMessage ? " -p:SuppressNETCoreSdkPreviewMessage=true" : string.Empty;
if (args.IndexOf("-- ", StringComparison.Ordinal) is int platformArgsIndex && platformArgsIndex > 0)
{
environmentVariables ??= [];
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
{
// Skip all unwanted environment variables.
string? key = entry.Key.ToString();
if (WellKnownEnvironmentVariables.ToSkipEnvironmentVariables.Contains(key, StringComparer.OrdinalIgnoreCase))
{
continue;
}

if (disableCodeCoverage)
{
// Disable the code coverage during the build.
if (CodeCoverageEnvironmentVariables.Contains(key, StringComparer.OrdinalIgnoreCase))
{
continue;
}
}

// We use TryAdd to let tests "overwrite" existing environment variables.
// Consider that the given dictionary has "TESTINGPLATFORM_UI_LANGUAGE" as a key.
// And also Environment.GetEnvironmentVariables() is returning TESTINGPLATFORM_UI_LANGUAGE.
// In that case, we do a "TryAdd" which effectively means the value from the original dictionary wins.
environmentVariables.TryAdd(key!, entry.Value!.ToString()!);
}
args = args.Insert(platformArgsIndex, extraArgs + " ");
}
else
{
args += extraArgs;
}

if (disableTelemetry)
{
environmentVariables.Add("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
}
return await CallTheMuxerAsync(args, environmentVariables, workingDirectory, failIfReturnValueIsNotZero, callerMemberName, cancellationToken);
}

string extraArgs = warnAsError ? " -p:MSBuildTreatWarningsAsErrors=true -p:TreatWarningsAsErrors=true" : string.Empty;
extraArgs += suppressPreviewDotNetMessage ? " -p:SuppressNETCoreSdkPreviewMessage=true" : string.Empty;
if (args.IndexOf("-- ", StringComparison.Ordinal) is int platformArgsIndex && platformArgsIndex > 0)
internal static async Task<CommandSlot> AcquireCommandSlotAsync(CancellationToken cancellationToken)
{
await s_maxOutstandingCommands_semaphore.WaitAsync(cancellationToken);
return default;
}

internal static Dictionary<string, string?> CreateEnvironmentVariables(
Dictionary<string, string?>? environmentVariables = null,
bool disableTelemetry = true,
bool disableCodeCoverage = true)
{
environmentVariables ??= [];
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
{
// Skip all unwanted environment variables.
string? key = entry.Key.ToString();
if (WellKnownEnvironmentVariables.ToSkipEnvironmentVariables.Contains(key, StringComparer.OrdinalIgnoreCase))
{
args = args.Insert(platformArgsIndex, extraArgs + " ");
continue;
}
else

if (disableCodeCoverage
&& CodeCoverageEnvironmentVariables.Contains(key, StringComparer.OrdinalIgnoreCase))
{
args += extraArgs;
continue;
}

return await CallTheMuxerAsync(args, environmentVariables, workingDirectory, failIfReturnValueIsNotZero, callerMemberName, cancellationToken);
// We use TryAdd to let tests "overwrite" existing environment variables.
// Consider that the given dictionary has "TESTINGPLATFORM_UI_LANGUAGE" as a key.
// And also Environment.GetEnvironmentVariables() is returning TESTINGPLATFORM_UI_LANGUAGE.
// In that case, we do a "TryAdd" which effectively means the value from the original dictionary wins.
environmentVariables.TryAdd(key!, entry.Value!.ToString()!);
}
finally

if (disableTelemetry)
{
s_maxOutstandingCommands_semaphore.Release();
environmentVariables.Add("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
}

return environmentVariables;
}

private static bool IsDotNetTestWithExeOrDll(string args)
Expand Down
Loading
Loading