From 3f5f36d617be02b098d636b60ff88c2becde630e Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 24 Jul 2024 22:33:24 -0400 Subject: [PATCH 1/2] Make TooDeepJsonDocument test more consistent across platforms Run the test on a thread with as consistent a stack size as possible so that we don't inadvertently succeed due to having a really large stack. --- .../Serialization/JsonElementTests.cs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs index 2a72b17d4d25ea..bc10810ac0477a 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs @@ -3,7 +3,8 @@ using System.Buffers; using System.IO; -using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Xunit; namespace System.Text.Json.Serialization.Tests @@ -219,9 +220,8 @@ public static void DeepEquals_NotEqualValuesReturnFalse(string value1, string va } [Theory] - [InlineData(10)] - [InlineData(100)] - [InlineData(500)] + [InlineData(5)] + [InlineData(50)] public static void DeepEquals_DeepJsonDocument(int depth) { using JsonDocument jDoc = CreateDeepJsonDocument(depth); @@ -229,12 +229,26 @@ public static void DeepEquals_DeepJsonDocument(int depth) Assert.True(JsonElement.DeepEquals(element, element)); } - [Fact] - public static void DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException() + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + public static async Task DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException() { - using JsonDocument jDoc = CreateDeepJsonDocument(10_000); - JsonElement element = jDoc.RootElement; - Assert.Throws(() => JsonElement.DeepEquals(element, element)); + var tcs = new TaskCompletionSource(); + new Thread(() => + { + try + { + using JsonDocument jDoc = CreateDeepJsonDocument(10_000); + JsonElement element = jDoc.RootElement; + Assert.Throws(() => JsonElement.DeepEquals(element, element)); + tcs.SetResult(true); + } + catch (Exception e) + { + tcs.SetException(e); + } + }, maxStackSize: 100_000) { IsBackground = true }.Start(); + + await tcs.Task; } private static JsonDocument CreateDeepJsonDocument(int depth) From 1351cfd846b7dfc19fa7ed36c7f2a6d6878e8995 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 25 Jul 2024 13:01:30 -0400 Subject: [PATCH 2/2] Disable test on mono --- .../System.Text.Json.Tests/Serialization/JsonElementTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs index bc10810ac0477a..aa4ee7597879fc 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs @@ -230,6 +230,7 @@ public static void DeepEquals_DeepJsonDocument(int depth) } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/105490", TestRuntimes.Mono)] public static async Task DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException() { var tcs = new TaskCompletionSource();