diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs index 1e23c37907d..933a376b994 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs @@ -520,10 +520,15 @@ public void DoNotLeakWeakReferences () // `Runtime.GetSurfacedObjects()` is process-global: NUnit/MTP // infrastructure (per-test TestExecutionContext, listeners, Console // capture, etc.) creates and releases transient Java.Lang.Object - // peers around every test, so the count drifts by a few entries - // between the snapshots below. Allow a small tolerance instead of - // requiring an exact count -- a real leak would dwarf this. - const int tolerance = 10; + // peers around every test, so the count drifts between snapshots. + // + // NativeAOT currently has a higher transient object count, so allow + // a wider tolerance there while keeping stricter checks elsewhere. + const int defaultTolerance = 10; + const int nativeAotTolerance = 30; + int tolerance = AppContext.TryGetSwitch ("Microsoft.Android.Runtime.RuntimeFeature.IsNativeAotRuntime", out bool isNativeAotRuntime) && isNativeAotRuntime + ? nativeAotTolerance + : defaultTolerance; WeakReference r = null; Exception threadException = null;