Skip to content

[ResourceLock] Narrow AzureFoundryChatClientProviderTests scope to EnvironmentVariables - #11053

Merged
Amaury Levé (Evangelink) merged 1 commit into
microsoft:mainfrom
nohwnd-bot:resource-lock/azure-foundry-chat-client-provider-tests-8543c63700863db1
Sep 5, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
microsoft:mainfrom
nohwnd-bot:resource-lock/azure-foundry-chat-client-provider-tests-8543c63700863db1

Conversation

@nohwnd-bot

Copy link
Copy Markdown
Contributor

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

Summary

Replaces a class-level [DoNotParallelize] with [ResourceLock(WellKnownResources.EnvironmentVariables)] on AzureFoundryChatClientProviderTests in test/UnitTests/Microsoft.Testing.Extensions.UnitTests.

Project: Microsoft.Testing.Extensions.UnitTests
Current parallelization scope: [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] (see Program.cs) — the assembly is already parallelized at method level.

Shared resource / conflicting tests: All 17 test methods in AzureFoundryChatClientProviderTests read and mutate the process-wide AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_DEPLOYMENT_NAME, and AZURE_OPENAI_API_KEY environment variables via Environment.SetEnvironmentVariable/GetEnvironmentVariable to drive AzureOpenAIChatClientProvider.IsAvailable. Each test already snapshots and restores the previous values in [TestInitialize]/[TestCleanup], but the raw Environment.SetEnvironmentVariable calls 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-known EnvironmentVariables resource key (the analyzer-mandated key for Environment.SetEnvironmentVariable mutations), 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 exactly WellKnownResources.EnvironmentVariables for any Environment.SetEnvironmentVariable call, and every test method (plus TestInitialize/TestCleanup) in this class performs such mutations, so a class-level lock correctly covers all of them under MethodLevel reacquisition semantics (no ClassInitialize/ClassCleanup state is involved).

Validation

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

  1. bash ./build.sh — Build succeeded, 0 errors, 0 warnings (the analyzer initially flagged the raw Environment.SetEnvironmentVariable calls with MSTEST0074 until [ResourceLock(WellKnownResources.EnvironmentVariables)] was added).
  2. 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.
  3. 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-1 was preserved across all commands above.

No assembly-level Parallelize/DoNotParallelize attribute 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.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 · 200.5 AIC · ⌖ 18.4 AIC · ⊞ 11.1K | [History]( · ◷)

…yChatClientProviderTests

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

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

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.

@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review September 5, 2026 20:10
@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Sep 5, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit a179d7c into microsoft:main Sep 5, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants