Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TooDeepJsonDocument test more consistent across platforms #105445

Merged
merged 2 commits into from
Jul 25, 2024
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
Loading