Repository navigation
[ResourceLock] Narrow [DoNotParallelize] to [ResourceLock] in OpenTelemetryProviderExtensionsTests - #11210
Merged
Amaury Levé (Evangelink) merged 1 commit intoSep 12, 2026
Conversation
…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>
Contributor
There was a problem hiding this comment.
🟢 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]withResourceLock(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.
Amaury Levé (Evangelink)
marked this pull request as ready for review
September 12, 2026 07:45
Amaury Levé (Evangelink)
enabled auto-merge (squash)
September 12, 2026 07:45
Amaury Levé (Evangelink)
approved these changes
Sep 12, 2026
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, followingthe exact pattern already established in this same test project by
AzureFoundryChatClientProviderTestsandTestingPlatformResourceDetectorTests.Selected candidate
test/UnitTests/Microsoft.Testing.Extensions.UnitTestsMethodLevel(already opted in viaProgram.cs)OpenTelemetryProviderExtensionsTests.csAddOpenTelemetryProviderFromEnvironment_RegistersProviderWithDelegateAndSkipsWhenSdkDisabledWellKnownResources.EnvironmentVariables), specificallyOTEL_SDK_DISABLED,OTEL_TRACES_EXPORTER,OTEL_METRICS_EXPORTER,OTEL_EXPORTER_OTLP_ENDPOINTread viaEnvironment.GetEnvironmentVariableinOpenTelemetryProviderExtensions.AddOpenTelemetryProviderFromEnvironment/ResolveEnvironmentConfiguration(src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/OpenTelemetryProviderExtensions.cs).Resource coverage matrix
System.Environment.Variables(OTEL_*)AddOpenTelemetryProviderFromEnvironment_RegistersProviderWithDelegateAndSkipsWhenSdkDisabled(realEnvironment.SetEnvironmentVariable)Environment.GetEnvironmentVariableinOpenTelemetryProviderExtensions.AddOpenTelemetryProviderFromEnvironmentResolveEnvironmentConfiguration_*tests in this file call the pure overload that takes an injectedFunc<string, string?>fake (Env(...)), never touching real process environment variables[ResourceLock(WellKnownResources.EnvironmentVariables)]on the method (new)System.Environment.Variables(AZURE_OPENAI_*)AzureFoundryChatClientProviderTestsAzureFoundryChatClientProviderreads viaEnvironment.GetEnvironmentVariable[ResourceLock(WellKnownResources.EnvironmentVariables)](pre-existing, unchanged)System.Environment.Variables(OTEL_SERVICE_NAME, CI markers)TestingPlatformResourceDetectorTestsTestingPlatformResourceDetectorreads viaEnvironment.GetEnvironmentVariable[ResourceLock(WellKnownResources.EnvironmentVariables)](pre-existing, unchanged)All three classes now share the same
WellKnownResources.EnvironmentVariableskey,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 realTracerProvider/ActivityListeneragainst the shared, unboundedMicrosoft.Testing.PlatformActivitySource, which aResourceLockkey cannotsafely 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
existing
WithEnvironmentAsynchelper (snapshot/neutralize/restore in afinally), so no additional state elimination was needed — only theattribute needed narrowing.
Mode = ResourceAccessMode.Readwas not used because this method both readsand writes environment variables (default write mode is correct).
[assembly: Parallelize]/[assembly: DoNotParallelize]/ scope /workers /
.runsettings/testconfig.jsonsettings 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):bash ./build.sh -c Debug— full Debug build succeeded (0 errors).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 anexisting 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.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.