Repository navigation
[ResourceLock] Narrow AzureFoundryChatClientProviderTests scope to EnvironmentVariables - #11053
Merged
Conversation
…yChatClientProviderTests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The lock covers initialization, test execution, and cleanup while allowing unrelated tests to run concurrently.
Pull request overview
Narrows test serialization to environment-variable consumers while preserving process-global state safety.
Changes:
- Replaces
[DoNotParallelize]with the environment-variable resource lock. - Documents the narrower parallelization behavior.
File summaries
| File | Description |
|---|---|
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/AzureFoundryChatClientProviderTests.cs |
Applies and explains the class-level environment-variable lock. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or 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 5, 2026 20:10
Amaury Levé (Evangelink)
enabled auto-merge (squash)
September 5, 2026 20:10
Amaury Levé (Evangelink)
approved these changes
Sep 5, 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
Replaces a class-level
[DoNotParallelize]with[ResourceLock(WellKnownResources.EnvironmentVariables)]onAzureFoundryChatClientProviderTestsintest/UnitTests/Microsoft.Testing.Extensions.UnitTests.Project:
Microsoft.Testing.Extensions.UnitTestsCurrent parallelization scope:
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)](seeProgram.cs) — the assembly is already parallelized at method level.Shared resource / conflicting tests: All 17 test methods in
AzureFoundryChatClientProviderTestsread and mutate the process-wideAZURE_OPENAI_ENDPOINT,AZURE_OPENAI_DEPLOYMENT_NAME, andAZURE_OPENAI_API_KEYenvironment variables viaEnvironment.SetEnvironmentVariable/GetEnvironmentVariableto driveAzureOpenAIChatClientProvider.IsAvailable. Each test already snapshots and restores the previous values in[TestInitialize]/[TestCleanup], but the rawEnvironment.SetEnvironmentVariablecalls are unsafe if two of these tests (or any other test in the assembly that also mutates environment variables) run concurrently, since the state is process-global.Why this attribute placement is minimal: The class previously carried
[DoNotParallelize], which serializes it against every other test in the assembly regardless of whether they touch the same resource. Replacing it with a class-level[ResourceLock(WellKnownResources.EnvironmentVariables)]narrows the effective conflict set to only the other tests in the assembly that declare the same well-knownEnvironmentVariablesresource key (the analyzer-mandated key forEnvironment.SetEnvironmentVariablemutations), while still fully serializing this class against itself and any other environment-variable mutator. This lets the class run in parallel with the large majority of tests in the assembly that never touch environment variables, without weakening the guarantee that made[DoNotParallelize]necessary in the first place.The class-level attribute is safe here because
MSTEST0074(UndeclaredProcessGlobalStateMutationAnalyzer) requires exactlyWellKnownResources.EnvironmentVariablesfor anyEnvironment.SetEnvironmentVariablecall, and every test method (plusTestInitialize/TestCleanup) in this class performs such mutations, so a class-level lock correctly covers all of them underMethodLevelreacquisition semantics (noClassInitialize/ClassCleanupstate is involved).Validation
Workflow run: https://github.com/microsoft/testfx/actions/runs/33946859894
bash ./build.sh— Build succeeded, 0 errors, 0 warnings (the analyzer initially flagged the rawEnvironment.SetEnvironmentVariablecalls withMSTEST0074until[ResourceLock(WellKnownResources.EnvironmentVariables)]was added).PATH="$PWD/.dotnet:$PATH" dotnet run --project test/UnitTests/Microsoft.Testing.Extensions.UnitTests -f net9.0 --no-build -c Debug -- --filter "FullyQualifiedName~AzureFoundryChatClientProviderTests"— Passed, 20/20 succeeded.PATH="$PWD/.dotnet:$PATH" dotnet run --project test/UnitTests/Microsoft.Testing.Extensions.UnitTests -f net9.0 --no-build -c Debug(full assembly, method-level parallel) — Passed, 1668 succeeded / 37 skipped / 0 failed out of 1705 total.DOTNET_CLI_TELEMETRY_SESSIONID=gha-65080725-33946859894-1was preserved across all commands above.No assembly-level
Parallelize/DoNotParallelizeattribute or other parallelization setting was added, removed, or changed; this project was already parallelized, and this change only narrows an existing class-level exclusion.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.