Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -219,22 +220,36 @@ 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);
JsonElement element = jDoc.RootElement;
Assert.True(JsonElement.DeepEquals(element, element));
}

[Fact]
public static void DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException()
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/105490", TestRuntimes.Mono)]
public static async Task DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException()
{
using JsonDocument jDoc = CreateDeepJsonDocument(10_000);
JsonElement element = jDoc.RootElement;
Assert.Throws<InsufficientExecutionStackException>(() => JsonElement.DeepEquals(element, element));
var tcs = new TaskCompletionSource<bool>();
new Thread(() =>
{
try
{
using JsonDocument jDoc = CreateDeepJsonDocument(10_000);
JsonElement element = jDoc.RootElement;
Assert.Throws<InsufficientExecutionStackException>(() => 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)
Expand Down