Repository navigation
Description
Failure
MediaAccessibility PR #26172, build 14698041, failed one Roslyn generator test:
Microsoft.Macios.Generator.Tests.Classes.ClassGenerationTests.GenerationTests
for the iOS UIKitPropertyTests input.
The expected Count getter contained:
UIKit.UIApplication.EnsureUIThread ();The generated output omitted only that line. The PR does not modify generator code or tests, and generator jobs on nearby PRs passed.
Root cause
CompilationExtensions.GetUINamespaces uses a process-global static uiNamespacesCache that is not scoped to a Roslyn Compilation or platform.
PR #22195 serialized BaseGeneratorTestClass.CompareGeneratedCode, but other tests can still replace the cache concurrently. In particular, CompilationExtensionsTest.GetUINamespacesTests calls GetUINamespaces (force: true) outside that lock. xUnit runs different test classes in parallel by default.
A macOS compilation can therefore replace the cache with a set that does not contain UIKit while an iOS generator test is running. BindingContext.NeedsThreadChecks then becomes false, which produces exactly the observed missing EnsureUIThread line.
Suggested fix
Prefer eliminating the process-global cache or making it compilation-specific, for example by associating the result with the Compilation.
As temporary containment, serialize every test that mutates or consumes this shared cache, or disable test parallelization for the affected collection. Add an interleaved iOS/macOS regression test.
Evidence
- Failing build: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=14698041
- Prior partial fix: [Rgen] Fix flacky tests when doing several compilations in parallel.Β #22195
- Affected cache:
src/rgen/Microsoft.Macios.Generator/Extensions/CompilationExtensions.cs - Emission gate:
src/rgen/Microsoft.Macios.Generator/Context/BindingContext.cs - Incomplete test lock:
tests/rgen/Microsoft.Macios.Generator.Tests/BaseGeneratorTestClass.cs - Unlocked force refresh:
tests/rgen/Microsoft.Macios.Generator.Tests/Extensions/CompilationExtensionsTest.cs
Activity
[rgen] Scope UI namespace cache per-compilation to fix generator flakβ¦