Skip to content

[ResourceLock] Narrow [DoNotParallelize] to [ResourceLock] in OpenTelemetryProviderExtensionsTests - #11210

Merged
Amaury Levé (Evangelink) merged 1 commit into
microsoft:mainfrom
nohwnd-bot:resource-lock/microsoft-testing-extensions-unittests-cd57d7f382a28d7b
Sep 12, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
microsoft:mainfrom
nohwnd-bot:resource-lock/microsoft-testing-extensions-unittests-cd57d7f382a28d7b

Conversation

@nohwnd-bot

Copy link
Copy Markdown
Contributor

gh-aw-workflow-id: resource-lock-refactoring

Summary

This is a small, incremental parallel-safety refactoring for
Microsoft.Testing.Extensions.UnitTests (already parallelized —
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]).

It replaces a broad [DoNotParallelize] on one test method with the narrower
[ResourceLock(WellKnownResources.EnvironmentVariables)] declaration, following
the exact pattern already established in this same test project by
AzureFoundryChatClientProviderTests and TestingPlatformResourceDetectorTests.

Selected candidate

  • Test project: test/UnitTests/Microsoft.Testing.Extensions.UnitTests
  • Current parallelization scope: MethodLevel (already opted in via Program.cs)
  • File changed: OpenTelemetryProviderExtensionsTests.cs
  • Method changed: AddOpenTelemetryProviderFromEnvironment_RegistersProviderWithDelegateAndSkipsWhenSdkDisabled
  • Shared resource: process-global environment variables (WellKnownResources.EnvironmentVariables), specifically OTEL_SDK_DISABLED, OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_EXPORTER_OTLP_ENDPOINT read via Environment.GetEnvironmentVariable in
    OpenTelemetryProviderExtensions.AddOpenTelemetryProviderFromEnvironment / ResolveEnvironmentConfiguration (src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/OpenTelemetryProviderExtensions.cs).

Resource coverage matrix

Resource Direct test writers (this class) Production readers/writers Tests invoking those production paths Declaration protecting each test
System.Environment.Variables (OTEL_*) AddOpenTelemetryProviderFromEnvironment_RegistersProviderWithDelegateAndSkipsWhenSdkDisabled (real Environment.SetEnvironmentVariable) Environment.GetEnvironmentVariable in OpenTelemetryProviderExtensions.AddOpenTelemetryProviderFromEnvironment Same method only — the other ResolveEnvironmentConfiguration_* tests in this file call the pure overload that takes an injected Func<string, string?> fake (Env(...)), never touching real process environment variables [ResourceLock(WellKnownResources.EnvironmentVariables)] on the method (new)
System.Environment.Variables (AZURE_OPENAI_*) Every test in AzureFoundryChatClientProviderTests AzureFoundryChatClientProvider reads via Environment.GetEnvironmentVariable All tests in that class Class-level [ResourceLock(WellKnownResources.EnvironmentVariables)] (pre-existing, unchanged)
System.Environment.Variables (OTEL_SERVICE_NAME, CI markers) Every test in TestingPlatformResourceDetectorTests TestingPlatformResourceDetector reads via Environment.GetEnvironmentVariable All tests in that class Class-level [ResourceLock(WellKnownResources.EnvironmentVariables)] (pre-existing, unchanged)

All three classes now share the same WellKnownResources.EnvironmentVariables key,
so they continue to serialize against each other and against the changed method,
which is required because the resource is process-wide. No other test in the
assembly calls Environment.SetEnvironmentVariable/GetEnvironmentVariable
(confirmed by grepping the whole project), so there is no uncovered observer.

The end-to-end test in the same file
(EndToEnd_InstrumentationAndResource_ExportSpanWithSemanticConventionTagsAndResource)
still carries [DoNotParallelize] and was not touched: it stands up a real
TracerProvider/ActivityListener against the shared, unbounded
Microsoft.Testing.Platform ActivitySource, which a ResourceLock key cannot
safely narrow (any concurrently running OpenTelemetry test in the assembly could
register another listener/exporter on the same source). This project already
stays sequential for that class, which is intentional and out of scope here.

Why the placement is minimal and complete

  • The method already fully isolates its own environment-variable state via the
    existing WithEnvironmentAsync helper (snapshot/neutralize/restore in a
    finally), so no additional state elimination was needed — only the
    attribute needed narrowing.
  • Mode = ResourceAccessMode.Read was not used because this method both reads
    and writes environment variables (default write mode is correct).
  • No [assembly: Parallelize] / [assembly: DoNotParallelize] / scope /
    workers / .runsettings / testconfig.json settings were added or changed.

Validation

Workflow run: https://github.com/microsoft/testfx/actions/runs/34675251928

Commands run (with DOTNET_CLI_TELEMETRY_SESSIONID=gha-65080725-34675251928-1):

  1. bash ./build.sh -c Debug — full Debug build succeeded (0 errors).
  2. bash ./build.sh -test -c Debug -projects "$PWD/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj" — ran the full unit-test project (net8.0 and net9.0 hosts); result: Tests succeeded for both target frameworks, 0 errors.

This is a unit-test project, so no -pack/acceptance-test run was required.

Note

This project is already parallelized (MethodLevel); this change narrows an
existing per-test exclusion rather than opting a new project into
parallelization.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • southcentralus0.in.applicationinsights.azure.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "southcentralus0.in.applicationinsights.azure.com"

See Network Configuration for more information.

Automated by the ResourceLock refactoring workflow. · auto · 596.7 AIC · ⌖ 10.5 AIC · ⊞ 11.9K | [History]( · ◷)

…erExtensionsTests

The environment-variable-mutating test in
Microsoft.Testing.Extensions.UnitTests now declares
[ResourceLock(WellKnownResources.EnvironmentVariables)] instead of
[DoNotParallelize], matching the pattern already used by
AzureFoundryChatClientProviderTests and
TestingPlatformResourceDetectorTests in the same project. This lets it
run in parallel with tests that never touch environment variables,
while still serializing against every other test in the assembly that
mutates them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 12, 2026 05:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues; the targeted lock preserves safe serialization.

Pull request overview

This PR narrows synchronization for an OpenTelemetry environment-variable test while preserving test safety.

Changes:

  • Replaces [DoNotParallelize] with ResourceLock(WellKnownResources.EnvironmentVariables).
  • Updates documentation describing the refined parallelization behavior.
File summaries
File Description
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/OpenTelemetryProviderExtensionsTests.cs Applies the targeted environment-variable resource lock and updates documentation.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review September 12, 2026 07:45
@Evangelink
Amaury Levé (Evangelink) merged commit 6e2db0e into microsoft:main Sep 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants