Skip to content

Commit 49e7fd5

Browse files
authored
Make TooDeepJsonDocument test more consistent across platforms (#105445)
* 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. * Disable test on mono
1 parent 4fbd498 commit 49e7fd5

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonElementTests.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
using System.Buffers;
55
using System.IO;
6-
using System.Linq;
6+
using System.Threading;
7+
using System.Threading.Tasks;
78
using Xunit;
89

910
namespace System.Text.Json.Serialization.Tests
@@ -219,22 +220,36 @@ public static void DeepEquals_NotEqualValuesReturnFalse(string value1, string va
219220
}
220221

221222
[Theory]
222-
[InlineData(10)]
223-
[InlineData(100)]
224-
[InlineData(500)]
223+
[InlineData(5)]
224+
[InlineData(50)]
225225
public static void DeepEquals_DeepJsonDocument(int depth)
226226
{
227227
using JsonDocument jDoc = CreateDeepJsonDocument(depth);
228228
JsonElement element = jDoc.RootElement;
229229
Assert.True(JsonElement.DeepEquals(element, element));
230230
}
231231

232-
[Fact]
233-
public static void DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException()
232+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
233+
[ActiveIssue("https://github.com/dotnet/runtime/issues/105490", TestRuntimes.Mono)]
234+
public static async Task DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException()
234235
{
235-
using JsonDocument jDoc = CreateDeepJsonDocument(10_000);
236-
JsonElement element = jDoc.RootElement;
237-
Assert.Throws<InsufficientExecutionStackException>(() => JsonElement.DeepEquals(element, element));
236+
var tcs = new TaskCompletionSource<bool>();
237+
new Thread(() =>
238+
{
239+
try
240+
{
241+
using JsonDocument jDoc = CreateDeepJsonDocument(10_000);
242+
JsonElement element = jDoc.RootElement;
243+
Assert.Throws<InsufficientExecutionStackException>(() => JsonElement.DeepEquals(element, element));
244+
tcs.SetResult(true);
245+
}
246+
catch (Exception e)
247+
{
248+
tcs.SetException(e);
249+
}
250+
}, maxStackSize: 100_000) { IsBackground = true }.Start();
251+
252+
await tcs.Task;
238253
}
239254

240255
private static JsonDocument CreateDeepJsonDocument(int depth)

0 commit comments

Comments
 (0)